Re: Advice On Building Dynamic MySQL Queries

From: Date: Fri, 20 Apr 2001 01:35:56 +0000
Subject: Re: Advice On Building Dynamic MySQL Queries
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-8737@lists.php.net to get a copy of this message
Hello JD, on 19.04.2001 you wrote: > I am building a query from a search form. This is the code I have now: > if (!empty($whereclause)) > { > $whereclause=urldecode($whereclause); > $whereclause=stripslashes($whereclause); > } > extract($HTTP_POST_VARS); > if (!empty($Price)) > { > if(empty($whereclause)) <--- blah blah blah ---> > It Just became apparent that I am going to need to add a whole bunch more > search criteria.. Does anyone have any advice/suggestions for getting rid of > all those if statements? > JD what about using a foreach statement and going through all the variables you need like this ? $myvars = array('Price', 'Stuff', 'Thing'); foreach ($myvars as $varname) { if (!empty($$varname)) { // do funky stuff here } } HTH Victor

« previous php.db (#8737) next »