manouche Posted March 9, 2010 Share Posted March 9, 2010 I have a form that uses a multi select dropdown. When submitted, I want to use those values to append to the query string. I already have the query string set up. For each value in the array, the appended query will be something like "AND color NOT LIKE '$c' " I populate the drop down dynamically with a query to a database. So, say that the multi select looks like this: <SELECT NAME ="color[]" multiple="multiple" SIZE="5"> <?php while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "<option value= \"$row\">$row</option>"; } ?> The code for the processing of the information looks like this: if ($color) { foreach ($color as $c) { $mainquery = "color NOT LIKE '$c' "; } } I can get one value of the array to append correctly, but that is all. I need it to somehow loop through the values of the array and append AND color NOT LIKE '$c'. So, ultimately, if red and blue were selected, it would say 'AND color NOT LIKE red and color NOT LIKE blue'. Can someone point me in the right direction? Thank you. Link to comment https://forums.phpfreaks.com/topic/194687-multi-select-drop-down-append-values-to-query/ Share on other sites More sharing options...
nafetski Posted March 9, 2010 Share Posted March 9, 2010 What you want to do is loop through your array, and concatenate those values onto your query. (You were really REALLY close) Change foreach ($color as $c) { $mainquery = "color NOT LIKE '$c' "; } to foreach ($color as $c) { $mainquery .= "color NOT LIKE '$c' AND "; } Notice the period before the equals sign, and the AND statement at the end of that. What you want is WHERE color NOT LIKE 'blue' AND COLOR NOT LIKE 'blue' AND COLOR NOT LIKE 'red' Good luck! Link to comment https://forums.phpfreaks.com/topic/194687-multi-select-drop-down-append-values-to-query/#findComment-1023890 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.