[thelist] PHP/MySQL search by multiple variables...

John Corry webshot at neoncowboy.com
Thu Aug 31 00:22:30 CDT 2000


I'm literally on the brink of writing the *necessary* parts for my first
PHP/MySQL app.
So far, I have a form that can be used to search a database by three
separate fields.

//relevant generation of query
//base query
$searchStmt = "SELECT *, hi_price, lo_price from $table where " ;

//plus concatenated query
if ($price_key)
   $searchStmt .= "price_key like '$price_key' and " ;
if ($title)
   $searchStmt .= "title like '$title' and " ;
if ($area)
   $searchStmt .= "area like '$area' and " ;

//minus the trailing 'and '
$stmt= substr($searchStmt, 0, strlen($searchStmt)-4) ;

But what I really need is to be able to search a broader section of the DB.
This works great if the user only selects one variable for each search
term...but how do I write it if they need to be able to select *multiple*
variables?

I guess multiple variables are an array...but I can't envision what to do
with it...

thanks,
John Corry





More information about the thelist mailing list