PHP: building query from array foreach

HelIos

New Member
\[code\]$test=$_POST['Cities']; foreach ($test as $t){ $query .= " AND u.bostadsort = \'".$t."\'"; }\[/code\]I have this for my\[code\]<select size="6" name="Cities[]" multiple="multiple"> <option value="">All</option> <option value="http://stackoverflow.com/questions/3856190/1">C1</option> <option value="http://stackoverflow.com/questions/3856190/2">C2</option> <option value="http://stackoverflow.com/questions/3856190/3">S3</option> <option value="http://stackoverflow.com/questions/3856190/4">S4</option> <option value="http://stackoverflow.com/questions/3856190/5">S5</option></select>\[/code\]But its not right at all.What I'm trying to do is when you pick the cities(in the search form), it puts all the values into an array. Now I would like to have it write like this, if you e.g pick 2, 4, 5\[code\]AND u.bostadsort = '2' OR u.bostadsort = '4' OR u.bostadsort = '5'\[/code\](maybe you could do this easier to, but this is the only way i know, using "OR")So if you picked more than 1 then it should be OR, instead of the AND i got.Maybe I done it in a wrong way, and there is a better method doing this than foreach..How can I do this?
 
Back
Top