Quoting Don Smith who wrote on Sat, Feb 17, 2001 at 08:56:19PM -0600:
> 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.
The smart way: building the query string on the fly. Something like:
$query="SELECT first,last,company FROM crews WHERE valid=1 ";
if ($q_firstname){
$query.="AND firstname like %$q_firstname% ";
}
if ($q_lastname){
$query.="AND lastname like %$q_lastname% ";
}
if ($q_company){
$query.="AND company like %$q_company% ";
}
$query.="ORDER BY entrydate";
$result=sybase_query($query);
Your query is a string too, use that fact :)
Koos
--
Koos van den Hout, PGP keyid RSA/1024 0xCA845CB5 via keyservers
[EMAIL PROTECTED] or DSS/1024 0xF0D7C263 -?)
Fax +31-30-2817051 Visit my site about books with reviews /\\
http://idefix.net/~koos/ http://www.virtualbookcase.com/ _\_V
--
PHP Database 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]