Kemik Posted August 27, 2007 Share Posted August 27, 2007 Hello, I want to do a query which selects the config.maps table.field WHERE ladder_id = $ladder_id. I can do this fine, but the next bit is slightly harder. The maps are stored as an array, separated by commas. I can explode these commas to put the maps in to an array called $maps but how can I then check that a value inputted from the drop down menu matches one of these maps? I cannot do: if ($dropdown = $maps[1] || $dropdown = $maps[2] || $dropdown = $maps[3]) { // Continue } As there could be anywhere between 1 and 5 or more maps in that array. Thanks for any help. EDIT: Come to think about it, I don't even need to do another query, as I already done the query to populate the drop down menu. I just need to know how to compare the variable to the array now. Link to comment https://forums.phpfreaks.com/topic/66877-drop-down-menu-validation-against-database/ Share on other sites More sharing options...
freeloader Posted August 28, 2007 Share Posted August 28, 2007 You're looking for the in_array function. In your case: if (in_array($dropdown, $maps)){ // the value $dropdown has been found in array $maps } You could also do a foreach loop going through the array. Watch out with the example you used. if ($dropdown = $maps[1] || Should be: if ($dropdown == $maps[1] || Link to comment https://forums.phpfreaks.com/topic/66877-drop-down-menu-validation-against-database/#findComment-336513 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.