Re: Best Way

From: Date: Sun, 18 Feb 2001 11:20:17 +0000
Subject: Re: Best Way
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-6723@lists.php.net to get a copy of this message
Just build the SQL statement with IFs... sql = "SELECT * FROM table WHERE "; if ($SearchByName) $sql .= "name = $Name AND "; if ($SearchBySurname) $sql .= "surname = $Surname AND "; if ($SearchByCompany) $sql .= "company = $Company AND "; ... then just remove the last four characters, and perform the query... Siggy ----- Original Message ----- From: "Don Smith" <don@newsvideo.com> To: <php-db@lists.php.net> Sent: Sunday, February 18, 2001 3:56 PM Subject: [PHP-DB] Best Way > I've searched the manual and read many examples, but I have to ask here for > the best way to program for a number of possibilities. I've got my site > working the hard way, but I'll bet there's a smarter way of doing the > following: > > Visitors to my site can search my database by lastname and/or firstname > and/or company. Is there a succinct way to checking for all possible > combinations? I alreay have NONE SELECTED covered, but the rest of the > possibilities are spotty. Too many IF statements, youknowwhaddimeanverne? > > SO... the user might just enter the last name, or just the first name, or > just the first and last, or just the company or just the last name and the > company.. and, oh well, you get the idea. Am I stuck with an awful lot of IF > statements or is there a smarter way of handling this? The site is > CameraCrews.com. Select "-by Name" to see the input page. > > Thanks for any help, > Don Smith > NewsVideo.com > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > For additional commands, e-mail: php-db-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > >

« previous php.db (#6723) next »