dynamic sql query

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dear 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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux