Zergman Posted November 3, 2008 Share Posted November 3, 2008 I have a listbox in my search page. What I would like to enable is to allow people to select multiple things from the list to add into the search query. Right now, it will only allow 1 item to be searched even if multiple items are selected. How do I go about changing it? Is it to do with the sql statement or the actual list box? SQL "SELECT * FROM `data` WHERE tdate between '$startdate%' and '$enddate%' AND t2agent LIKE '$t2agent%' AND flagentTID LIKE '$flagent%' AND resolution LIKE '$conclusion%' AND rescomments LIKE '$conclusioncomments%' AND prov LIKE '$prov%' AND valid LIKE '$valid%' AND level1 LIKE '$level1%' AND level2 LIKE '$level2%' AND level3 LIKE '$level3%' AND notes LIKE '$notes%' ORDER BY tdate" Box <select name="validmenu" class="inputbox" id="validmenu" size="5" multiple> <option value="%" selected="selected">All</option> <option value="*Valid*">*Valid*</option> <option value="Behaviour">Behaviour</option> <option value="Improper Abstract">Improper Abstract</option> <option value="Improper Route">Improper Route</option> <option value="Invalid STN">Invalid STN</option> <option value="Kudos">Kudos</option> <option value="Other">Other</option> <option value="Policy/Procedure">Policy/Procedure</option> <option value="Poor Ticket Creation">Poor Ticket Creation</option> <option value="Troubleshooting">Troubleshooting</option> </select> Quote Link to comment https://forums.phpfreaks.com/topic/131249-using-listbox-in-search-page/ Share on other sites More sharing options...
fenway Posted November 3, 2008 Share Posted November 3, 2008 You'll need to use an IN() for the mysql... and you'll have to get php to give you a comma-separated array. Quote Link to comment https://forums.phpfreaks.com/topic/131249-using-listbox-in-search-page/#findComment-681465 Share on other sites More sharing options...
Zergman Posted November 3, 2008 Author Share Posted November 3, 2008 Thanks fenway I did this for the array and its gathering it fine @$validity= $_GET['validmenu']; if( is_array($validity)){ while (list ($key, $val) = each ($validity)) { echo "$val <br>"; } }//else{echo "not array";} But not sure on how to do the in() thing. Checked google and not coming up with much. Got any resources on it that you could share? Quote Link to comment https://forums.phpfreaks.com/topic/131249-using-listbox-in-search-page/#findComment-681499 Share on other sites More sharing options...
Zergman Posted November 3, 2008 Author Share Posted November 3, 2008 tried to do ...valid IN ('$val')... in my sql but search is coming up with nothing now Quote Link to comment https://forums.phpfreaks.com/topic/131249-using-listbox-in-search-page/#findComment-681509 Share on other sites More sharing options...
Zergman Posted November 3, 2008 Author Share Posted November 3, 2008 Okay, realized my array wasn't properly done. Not comma-separated Still working on that. Tested my IN() and its working when I directly enter the values into the sql statement so its just the array I need to fix Quote Link to comment https://forums.phpfreaks.com/topic/131249-using-listbox-in-search-page/#findComment-681532 Share on other sites More sharing options...
Zergman Posted November 3, 2008 Author Share Posted November 3, 2008 k, just realized I have no idea how to make a comma-separated array :/ Quote Link to comment https://forums.phpfreaks.com/topic/131249-using-listbox-in-search-page/#findComment-681551 Share on other sites More sharing options...
Zergman Posted November 3, 2008 Author Share Posted November 3, 2008 This is what I got so far from the gigerweb, not working as im sure you'll see. Due to my extreme lack of php or programming knowledge, not sure what im doing here. $list = "$_GET['validmenu']"; $array = explode(',',$list); As the good ol' Captain from the Simpsons would say, "Arr... I don't know what im doin" Quote Link to comment https://forums.phpfreaks.com/topic/131249-using-listbox-in-search-page/#findComment-681606 Share on other sites More sharing options...
fenway Posted November 4, 2008 Share Posted November 4, 2008 Please echo the current sql statement you're generating. Quote Link to comment https://forums.phpfreaks.com/topic/131249-using-listbox-in-search-page/#findComment-681742 Share on other sites More sharing options...
Zergman Posted November 6, 2008 Author Share Posted November 6, 2008 Not sure what you mean by the sql statement im generating. If you mean the sql statement itself, this is it. SELECT * FROM `data` WHERE tdate between '$startdate%' and '$enddate%' AND t2agent LIKE '$t2agent%' AND flagentTID LIKE '$flagent%' AND resolution LIKE '$conclusion%' AND rescomments LIKE '$conclusioncomments%' AND prov LIKE '$prov%' AND valid IN ('$valid') AND level1 LIKE '$level1%' AND level2 LIKE '$level2%' AND level3 LIKE '$level3%' AND notes LIKE '$notes%' ORDER BY tdate When I echo the sql statement after a query, it only shows the last option I select in the list box, nothing else before that. SELECT * FROM `data` WHERE tdate between '2008-10-30%' and '2008-11-06%' AND t2agent LIKE '%' AND flagentTID LIKE '%' AND resolution LIKE '%%' AND rescomments LIKE '%' AND prov LIKE '%' AND valid LIKE 'Improper Abstract%' AND level1 LIKE '%%' AND level2 LIKE '%' AND level3 LIKE '%' AND notes LIKE '%' ORDER BY tdate There were 2 other options I selected before Improper Abstract Quote Link to comment https://forums.phpfreaks.com/topic/131249-using-listbox-in-search-page/#findComment-683841 Share on other sites More sharing options...
fenway Posted November 6, 2008 Share Posted November 6, 2008 I was looking for the latter. You should not include fields that aren't being searched... you can use php to figure that out. And for your validmenu options, you need implode, not explode. Quote Link to comment https://forums.phpfreaks.com/topic/131249-using-listbox-in-search-page/#findComment-683859 Share on other sites More sharing options...
Zergman Posted November 6, 2008 Author Share Posted November 6, 2008 I really appreciate the advise fenway, really do. I am by no means knowledgeable with this stuff ... which is why I do stuff like my search stuff. I just know what I know right now, but always trying to learn how to do stuff better as I go I'll look into that for sure! So should this work then? $list = "$_GET['validmenu']"; $array = implode(',',$list); Sorry for asking, but having a hard time finding out the proper information for this and I don't have access right now to my test server Quote Link to comment https://forums.phpfreaks.com/topic/131249-using-listbox-in-search-page/#findComment-683884 Share on other sites More sharing options...
Zergman Posted November 6, 2008 Author Share Posted November 6, 2008 Just going through the implode() manual, would this be better? $list = array('$_GET['validmenu']'); $array = implode(",", $list); Quote Link to comment https://forums.phpfreaks.com/topic/131249-using-listbox-in-search-page/#findComment-683900 Share on other sites More sharing options...
fenway Posted November 6, 2008 Share Posted November 6, 2008 Don't know... try both. Quote Link to comment https://forums.phpfreaks.com/topic/131249-using-listbox-in-search-page/#findComment-684048 Share on other sites More sharing options...
Zergman Posted November 6, 2008 Author Share Posted November 6, 2008 This is where my lack of experience shows. Getting syntax error on $list = array('$_GET['validmenu']'); and $list = "$_GET['validmenu']"; Not sure whats wrong Quote Link to comment https://forums.phpfreaks.com/topic/131249-using-listbox-in-search-page/#findComment-684059 Share on other sites More sharing options...
xtopolis Posted November 7, 2008 Share Posted November 7, 2008 $list = array($_GET['validmenu']); or $list = $_GET['validmenu']; Can't enclose the variables in single quotes. It would read it as the word, not the object. Quote Link to comment https://forums.phpfreaks.com/topic/131249-using-listbox-in-search-page/#findComment-684330 Share on other sites More sharing options...
Zergman Posted November 7, 2008 Author Share Posted November 7, 2008 Thanks for the correction xtopolis So this is where it stands right now. Information and help pulled from here and the php manual. This is what I got to gather the data from the listbox and create a comma seperated array. $list = array($_GET['validmenu']); $array = implode(",", $list); echo $array; It gathers only 1 option from the listbox even if I select 2 or more. Read somewhere that in the select box, I need to do a [] in the name. Not sure on this. <select name="validmenu[]" class="inputbox" id="validmenu" size="4" multiple> In my sql statement, im using valid IN ('$array') With all this, when I try it out, the listbox will take only 1 option that I select and puts it in the sql statment as it should. So it looks like my problems are in getting the data into the comma seperated array. .... I think. ugh Quote Link to comment https://forums.phpfreaks.com/topic/131249-using-listbox-in-search-page/#findComment-684692 Share on other sites More sharing options...
fenway Posted November 7, 2008 Share Posted November 7, 2008 Your field name has now changed on the html input form. Quote Link to comment https://forums.phpfreaks.com/topic/131249-using-listbox-in-search-page/#findComment-684695 Share on other sites More sharing options...
Zergman Posted November 7, 2008 Author Share Posted November 7, 2008 Your field name has now changed on the html input form. Are you referring to the name="validmenu[]" ? Wasn't sure on the [], read somewhere it was needed for the array but I couldn't tell ya. Removing the [] doesn't seem to affect it Quote Link to comment https://forums.phpfreaks.com/topic/131249-using-listbox-in-search-page/#findComment-684703 Share on other sites More sharing options...
fenway Posted November 7, 2008 Share Posted November 7, 2008 This is really a php question.... I will move it shortly. Quote Link to comment https://forums.phpfreaks.com/topic/131249-using-listbox-in-search-page/#findComment-684795 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.