RE: [PHP] Filters

From: Date: Sat, 25 Nov 2000 10:53:45 +0000
Subject: RE: [PHP] Filters
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-27126@lists.php.net to get a copy of this message
On 25-Nov-00 Alvin Tan wrote: > Hi all, > > Newbie question. I've built a simple db and am able to add and edit. my > problem is how can i do a select staetment that filters according to my 3 > drop-down lists. (name, genre, medium) if only one of the 3 is selected, > then all records in that filed is shown, if 2, then only if both conditions > match, etc. i'm trying out different stuff but i just need a little 'nudge' > in the right direction, thanks. > // <nudge> $qry=" select foo from my_table"; addclause($qry, 'name', $name); addclause($qry, 'genre', $genre); addclause($qry, 'medium', $medium); $res=mysql_query($qry); function addclause(&$qry, $fld, $val) { if ($val) { $qry .=sprintf(" %s $fld='%s'", ( preg_match("#\bwhere\b#mi", $qry) ? 'and' : 'where'), $val); } return($qry); } // </nudge> Regards, -- Don Read dread@texas.net -- The problem with people who have no vices is that you can be sure they're going to have some pretty annoying virtues.

« previous php.general (#27126) next »