creating a SELECT AND query

From: Date: Tue, 18 Apr 2006 11:03:19 +0000
Subject: creating a SELECT AND query
Groups: php.general 
Request: Send a blank email to php-general+get-234169@lists.php.net to get a copy of this message
I have a textboxt which searches for the surname of a client. A SELECTBOX searches for the area. I am trying to generate a query that searches all of scotland (when area=a) and by area (say I live in area 16= "edinburgh") and combine this with the name search select name="area" class="text" id="area"> <option value="a">All of Scotland</option> <option value='1'>Aberdeen City Counci...</option> <option value='16'>Edinburgh City Counc...</option> <option value='17'>Falkirk Council</option> <option value='18'>Fife Council</option> <option value='19'>Glasgow City Council</option> <option value='20'>Highland Council</option> <option value='21'>Inverclyde Council</option> <option value='22'>Midlothian Council</option> <option value='23'>Moray Council</option> </select> This is what I thought would work.. $query1= "select * from $table_name WHERE sname LIKE '$search_string%' "; if ($area="a") { $query1 .=" AND area='a'"; } else { $query1 .="AND area='$area'"; }

« previous php.general (#234169) next »