dynamic sql query
am 07.07.2008 16:53:27 von Beth TuckerDear Nasreen,
You could also do something like this:
$query = "select * FROM gig g, venue v, genre ge ";
if($gig_name) {
$wheres[] = "g.gigName LIKE '%".$gig_name."%'";
}
if($gig_date) {
$wheres[] = "g.gig_date LIKE '%".$sdate."%'";
}
if(is_array($wheres)) {
$wheres = implode(" OR ", $wheres);
$query .= " WHERE $wheres";
}
This has fewer if statements than basing it off of the number of fields and then checking if a value exists to add the " OR " between the statements.
Beth
--
Beth Tucker
php|architect Trainer
http://www.phparch.com/phptraining/
Check out the latest issue of
php|architect Magazine:
http://www.phparch.com/c/phpa/magazine/current/
Join us in Atlanta, GA, November 12 - 14, 2008
Explore the Possibilities at php|works
Call for papers open until July 25th
http://phpworks.mtacon.com/
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php