Jump to content

[SOLVED] Help with array


Zergman

Recommended Posts

Again, sorry for being a complete newb on this stuff.

 

So if I understand you right, It would be best to put the code in my page after the select box?

 

EDIT: tried that, no change.

 

Reading your notes again, I think you mean the VALUE has to exist in $valid before implode comes into play which is why it errors until data is put in and the query is submitted ..... i think

You just need to do something like:

<?php
if (isset($_GET['name_of_submit_button'])) {

    $orderedby = $_GET['sortby'];
    $lvl2display = $_GET['lvl2'];
    $startdate = $_GET['startdatefield'];
    $enddate = $_GET['enddatefield'];
    $t2agent = $_GET['nsagentfield'];
    $flagent = $_GET['frontlineagentfield'];
    $conclusion = $_GET['conclusionmenu'];
    $conclusioncomments = $_GET['conclusioncomments'];
    $prov = $_GET['radio'];
    $CBBC = $_GET['BC'];
    $valid = $_GET['validmenu'];
    $level1 = $_GET['country'];
    $level2 = $_GET['state'];
    $level3 = $_GET['city'];
    $notes = $_GET['notesfield'];

    $comma_separated = implode(",", $_GET['validmenu']);
    echo $comma_separated;
}
?>

 

If you try to access $_GET, but the form has not been submitted (like on a blank page load), then $_GET is undefined and will give you errors.

Awesome, thanks flyhoney!

 

Just one last problem with all this and I think it should be good to go.

 

When I put in that code flyhoney, I am now getting a sql syntax error.

 

Pardon my newbish sql statment :)

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 ($comma_separated) AND level1 LIKE '$level1%' AND level2 LIKE '$level2%' AND level3 LIKE '$level3%' AND notes LIKE '$notes%' ORDER BY tdate

 

says its dealing with my "valid IN ($comma_separated)" part.

 

Can you post an example of the complete query?  If $comma_separated is an empty string you might have to set $comma_separated = "''" to make the query valid.

 

Maybe something like this:

<?php
if (isset($_GET['validmenu'])) {
    $comma_separated = implode("','", $_GET['validmenu']);
} else {
    $comma_separated = "''"; // or maybe some default value,  like "'default'"
}
?>

Wicked, that got rid of the error nicely flyhoney!

 

Only thing now LOL. .... it never ends with me .... is that my default doesn't work.  Im assuming this is 100% due to my ability to write poor code.

 

In my select box, I have sorta a default selection.  This is my box.

<select name="validmenu[]" class="inputbox" id="validmenu" size="4" 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>

 

When All is selected, the query won't go.  Only when other options are selected.

 

What would be best to use with IN() to make it search all?

 

the query looks like this when All is selected which won't work

valid IN ('%')

 

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.