dynamic sql query

From: Date: Mon, 07 Jul 2008 14:53:27 +0000
Subject: dynamic sql query
Groups: php.db 
Request: Send a blank email to php-db+get-45126@lists.php.net to get a copy of this message
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/

« previous php.db (#45126) next »