Damn, if I'd a known it was that easy ;)
Thanks for the help, works great now.
Jerry Lake - [EMAIL PROTECTED]
Web Designer
Europa Communications - http://www.europa.com
Pacifier Online - http://www.pacifier.com
-----Original Message-----
From: Jason Lotito [mailto:[EMAIL PROTECTED]]
Sent: Thursday, April 05, 2001 7:09 PM
To: Jerry Lake; [EMAIL PROTECTED]
Subject: RE: [PHP] better functionality in query ?
> I'm in process of creating a online whitepages directory for
> a small town phone company and I am having a little difficulty
> in refining my selection. My search form has two fields; last
> and first name. I would like to be able to have more of a wild
> card approach and some refinement when a user enters both a
> first and last name. I am unsure how to go about this, should
> I restructure my query, or make changes to my PHP. here is the
> query I am currently using. and the site is located at
> http://whitepages.maadtelco.com/ any assistance/direction is certainly
> appreciated.
>
> <snip>
> $query = "select * from whitepages WHERE last_name LIKE '$last_name' ORDER
> BY last_name" or die("Nothing to see here");
> </snip>
$query = "SELECT * FROM whitepages WHERE last_name LIKE '%$last_name%' ORDER
BY last_name" or die("Nothing to see here");
Question, why are you 'die'ing on a variable assigntment? Wouldn't you want
to 'die' on the actualy db_query()?
Note the added '%', this is assuming you are using MySQL, though they are
generally the same, I believe, with other DB's. The % is essentially
wildcard of any amount. So, if the last_name was BOB
it would find
BOBBY
BOBBER
ADOBOB
$query = "SELECT * FROM whitepages WHERE last_name LIKE '%$last_name%'
$andor first_name LIKE '%$first_name' ORDER
BY last_name" or die("Nothing to see here");
In this query, we are including the First Name. In this, we are also using
the $andor variable, which you can define as AND, or OR, or allow the user
to define it by using a radio box or the like when making the search. I
suggest setting a default of OR for the variable $andor.
Jason Lotito
www.NewbieNetwork.net
Where those who can, teach;
and those who can, learn.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]