PHP: building query from array foreach
<pre><code>$test=$_POST['Cities'];
 foreach ($test as $t){
 $query .= " AND u.bostadsort = \'".$t."\'";
 }
</code></pre>

<p>I have this for my</p>

<pre><code>&lt;select size="6" name="Cities[]" multiple="multiple"&gt;
    &lt;option value=""&gt;All&lt;/option&gt;
    &lt;option value="1"&gt;C1&lt;/option&gt;
    &lt;option value="2"&gt;C2&lt;/option&gt;
    &lt;option value="3"&gt;S3&lt;/option&gt;
    &lt;option value="4"&gt;S4&lt;/option&gt;
    &lt;option value="5"&gt;S5&lt;/option&gt;
&lt;/select&gt;
</code></pre>

<p>But its not right at all.</p>

<p>What I'm trying to do is when you pick the cities(in the search form), it puts all the values into an array. </p>

<p>Now I would like to have it write like this, if you e.g pick 2, 4, 5</p>

<pre><code>AND u.bostadsort = '2' OR u.bostadsort = '4' OR u.bostadsort = '5'
</code></pre>

<p>(maybe you could do this easier to, but this is the only way i know, using "OR")</p>

<p>So if you picked more than 1 then it should be OR, instead of the AND i got.</p>

<p>Maybe I done it in a wrong way, and there is a better method doing this than foreach..</p>

<p>How can I do this?</p>
