[thelist] [PHP/MySQL] building a select statement from a mutilple select field
Burhan Khalid
thelist at meidomus.com
Mon Aug 1 02:53:39 CDT 2005
On Jul 27, 2005, at 9:30 PM, Hassan Schroeder wrote:
> Jeremy Weiss wrote:
>
>
>> I've got a multiple select form box that lists several cities ...
>>
>
>
>> The problem is, when multiple cities are selected, my sql
>> statement comes out like:
>> SELECT * FROM cba_condo WHERE ... AND city = 'Biloxi' AND city =
>> 'Diamondhead' AND city = 'Gulfport' AND city = 'Lakeshore' ORDERBY
>> price Desc;
>>
>
> I don't do much PHP, but you might want to look at generating your
> statement like
>
> ... AND city IN ('Biloxi','Diamondhead','Gulfport','Lakeshore') ...
And an easy way to do the above is :
$cities = array('Biloxi','Diamondhead','Gulfport','Lakeshore');
$sql = "(".implode(",",$cities).")";
Assuming your cities are nicely arranged in an array.
More information about the thelist
mailing list