[PHP] creating a SELECT AND query
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=aAll 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'; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] creating a SELECT AND query
On 18/04/06, Ross [EMAIL PROTECTED] wrote: $query1= select * from $table_name WHERE sname LIKE '$search_string%' ; if ($area=a) { $query1 .= AND area='a'; } else { $query1 .=AND area='$area'; } Firstly, you're assigning a to area rather than testing whether $area is a. You need a == operator, not a =. Secondly, even if you were testing $area properly, you're doing the same thing in both halves of the if-statement. Which isn't very useful. Really, you only need the AND area='?' part if $area is not equal to a: if ($area != a) { $query1 .= AND area='$area'; } -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] creating a SELECT AND query
On Tue, April 18, 2006 6:03 am, Ross wrote: select name=area class=text id=area option value=aAll of Scotland/option option value='1'Aberdeen City Counci.../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'; If $area is 'a', they want ALL of Scotland. Since your table probably has ONLY Scotland in it, you don't want to restrict anything there. For sure, the area isn't going to be 'a' in your table, is it? Cuz the next line or two seem to indicate that area is a number like '1' for Aberdeen City Council and so on. If you're thinking of adding, say, Wales, next month/year, then you need to have a different field from 'area' and put in the restriction here for getting just Scotland. If you just plain don't care about adding anything more ever, you can just take out the line above. } else { $query1 .=AND area='$area'; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php