PHP - two multiple select dropdowns, passing user selections into a MySQL query

enzo1980

New Member
EDIT:The drop down menus have the following listed in them:Typing CourseDaily Marketing CourseWhen using the code below to add selected text form the dropdown into the MySQL statement, only the first word appears ie. 'Typing' and 'Daily', the code looks like this:\[code\]SELECT * FROM `acme` WHERE `course` IN('Typing', 'Daily')AND `date` IN('2010-08-27', '2010-08-31')\[/code\]it should be this:\[code\]SELECT * FROM `acme` WHERE `course` IN('Typing Course', 'Daily Marketing Course')AND `date` IN('2010-08-27', '2010-08-31')\[/code\]Original question below:Hi all,Ok, I'll do my best to explain what I would like to do.I have two dropdown menus set to multiple, the first is Course and the second is Date, here is the code that populates each dropdown:Course\[code\]echo "<select name='course' value='' multiple='multiple'>"; // printing the list box select command echo "<option value=''>All</option>"; while($ntc=mysqli_fetch_array($queryc)){//Array or records stored in $nt echo "<option value=http://stackoverflow.com/questions/3635370/$ntc[course]>$ntc[course]</option>"; /* Option values are added by looping through the array */ } echo "</select>";// Closing of list box \[/code\]Date\[code\]echo "<select name='date' value='' multiple='multiple'>"; // printing the list box select command echo "<option value=''>All</option>"; while($nt=mysqli_fetch_array($queryr)){//Array or records stored in $nt echo "<option value=http://stackoverflow.com/questions/3635370/$nt[dates]>$nt[dates]</option>"; /* Option values are added by looping through the array */ } echo "</select>";// Closing of list box \[/code\]The main problem I have is passing the results of each dropdown to a MySQL query. For example, if a user select from the Course dropdown 'Typing' AND 'Marketing' - I need the MySQL query to be:\[code\]SELECT * FROM acme WHERE course = 'Typing' OR course = 'Marketing'\[/code\]In addition, I also need to add the second dropdown into the equation, so working on the assumption the user has selected 'Typing' AND 'Marketing', they then select 21-06-2010 from the Date dropdown, so the query then needs to be:\[code\]SELECT * FROM acme WHERE course = 'Typing' OR course = 'Marketing' AND date = '21-06-2010' OR date = '18-05-2010'\[/code\]Clearly, I also need to build in if they select more than one date form the dropdown.I hope I have explained clearly enough what I'm looking to achieve..any and all help gratefully received. Really struggling to get my head around this one.Thanks in advance,Homer.
 
Back
Top