aashcool198 Posted December 8, 2009 Share Posted December 8, 2009 HI.. my form has one multiple select dropdown box which gives me selected values in an array. I want to know how can i write mysql query so that i get all the results in which any of the selected case is possible. for example if my array is arr[] than i want to write $result = mysql_query("select * from student where name=arr[0] or name= arr[1] or name=arr[2]....so on...."); I don't know how many elements are there in the array hence can't write it directly.. how can i do it? Link to comment https://forums.phpfreaks.com/topic/184387-how-to-use-multiple-select-drop-down/ Share on other sites More sharing options...
cags Posted December 8, 2009 Share Posted December 8, 2009 A simple method... $sql = "SELECT * FROM student WHERE name='" implode("' or name='", $arr) . "'"; Note: You should filter $arr first for dangerous content using an in_array whitelist. Link to comment https://forums.phpfreaks.com/topic/184387-how-to-use-multiple-select-drop-down/#findComment-973374 Share on other sites More sharing options...
aashcool198 Posted December 8, 2009 Author Share Posted December 8, 2009 You simply cracked it! thanks a lot! Link to comment https://forums.phpfreaks.com/topic/184387-how-to-use-multiple-select-drop-down/#findComment-973450 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.