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
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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.