RE: [PHP] better functionality in query ?

From: Date: Fri, 06 Apr 2001 03:46:04 +0000
Subject: RE: [PHP] better functionality in query ?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-47357@lists.php.net to get a copy of this message
> > > 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 > On Thu, Apr 05, 2001 at 04:51:47PM -0700, Jerry Lake wrote: > > Damn, if I'd a known it was that easy ;) > > Thanks for the help, works great now. > > > -----Original Message----- > From: Joe Stump [mailto:miester@php.net] > NOTE(!): LIKE '%foo%' DOES NOT SCALE. It looks like you are > making a phone book, > which could get to be a lot of numbers. On the other hand 'foo%' > oddly scales to > hundreds of thousands of records without any problems (make sure > it's key'd!). > > Which should work fine in your instance - just have people type > in the first > 4 letters of the persons name. > > --Joe > Very true, good point. Good thing to keep in mind, and something I overlooked. Jason Lotito www.NewbieNetwork.net Where those who can, teach; and those who can, learn.

« previous php.general (#47357) next »