Jump to content

Using listbox in search page


Zergman

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/131249-using-listbox-in-search-page/
Share on other sites

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?

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" :(

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

 

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.