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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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'"
}
?>

Link to comment
Share on other sites

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 ('%')

 

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.