Multiple Multiple Select Boxes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • murraymiken@yahoo.com

    Multiple Multiple Select Boxes

    I'm looking to have multiple multiple-select-boxes on a page. But I
    can only get the contents from the last selected value within a box,
    via PHP. I've tried numerous methods.
    What am I doing wrong?

    You can see ALL the values present in the url:

    e.g.

    Box[2]
    1 aaa <-this is selected by user, but missing when processed by php.
    2 bbb <-this is selected by user.
    3 ccc
    4 ddd

    Box[4]
    1 aaa
    2 bbb
    3 ccc <-this is selected by user.
    4 ddd

    Box[6]
    1 aaa
    2 bbb
    3 ccc
    4 ddd <-this is selected by user.

    My code returns:
    Box=2, Id=2
    Box=4, Id=3
    Box=6, Id=4

    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html;
    charset=iso-8859-1">
    <title>Help Desk - Admin panel - Ticket options</title>
    </head>
    <body>
    <form name="cat_list" method="get" action="test.ph p">
    <table width="100%" border="0" cellpadding="0" cellspacing="0" >
    <!--DWLayoutTable-->
    <tr>
    <td valign="top" class="content1 " style="border-width: 1px 1px 0px
    0px;"><!--<input style="width: 100px;" value="{murra31 5}"></td>-->

    <select name="notify_us er_id[2]" multiple size="4" style="width:
    307px;">
    <option selected value="1"> aaa</option>
    <option selected value="2"> bbb</option>
    <option value="3"> ccc</option>
    <option value="4"> ddd</option>

    </select>
    </td>

    </tr>

    <tr>
    <td valign="top" class="content1 " style="border-width: 1px 1px 0px
    0px;"><!--<input style="width: 100px;" value="{murra31 5}"></td>-->

    <select name="notify_us er_id[4]" multiple size="4" style="width:
    307px;">
    <option value="1"> aaa</option>
    <option value="2"> bbb</option>
    <option selected value="3"> ccc</option>
    <option value="4"> ddd</option>

    </select>
    </td>
    </tr>

    <tr>
    <td valign="top" class="content1 " style="border-width: 1px 1px 0px
    0px;"><!--<input style="width: 100px;" value="{murra31 5}"></td>-->

    <select name="notify_us er_id[6]" multiple size="4" style="width:
    307px;">
    <option value="1"> aaa</option>
    <option value="2"> bbb</option>
    <option value="3"> ccc</option>
    <option selected value="4"> ddd</option>
    </select>
    </td>
    <tr align="center" valign="middle" >
    <td height="20" colspan="5" class="content2 "
    style="border-width: 1px 0px 0px 0px;"><input name="btn_updca ts"
    type="submit" id="btn_updcats " value="Update">
    <input name="btn_delca ts" type="submit" id="btn_delcats "
    value="Delete"> </td>
    </tr>
    </tr>
    <table>
    </form>
    </body>
    </html>

    PHP -------------------------
    <?php

    if (is_array($_GET["notify_user_id "]))
    {

    foreach($_GET['notify_user_id '] as $id=>$col_val)
    {
    $aRay = array($col_val) ;
    foreach($aRay as $id2=>$col_val2 )
    {
    echo "Box=".$id. ", Id=".$col_val2. "<br>";
    }

    }
    }


    ?>

  • ZeldorBlat

    #2
    Re: Multiple Multiple Select Boxes


    murraymiken@yah oo.com wrote:[color=blue]
    > I'm looking to have multiple multiple-select-boxes on a page. But I
    > can only get the contents from the last selected value within a box,
    > via PHP. I've tried numerous methods.
    > What am I doing wrong?
    >
    > You can see ALL the values present in the url:
    > http://myserver/test.php?notify_user...updcats=Update
    > e.g.
    >
    > Box[2]
    > 1 aaa <-this is selected by user, but missing when processed by php.
    > 2 bbb <-this is selected by user.
    > 3 ccc
    > 4 ddd
    >
    > Box[4]
    > 1 aaa
    > 2 bbb
    > 3 ccc <-this is selected by user.
    > 4 ddd
    >
    > Box[6]
    > 1 aaa
    > 2 bbb
    > 3 ccc
    > 4 ddd <-this is selected by user.
    >
    > My code returns:
    > Box=2, Id=2
    > Box=4, Id=3
    > Box=6, Id=4
    >
    > <html>
    > <head>
    > <meta http-equiv="Content-Type" content="text/html;
    > charset=iso-8859-1">
    > <title>Help Desk - Admin panel - Ticket options</title>
    > </head>
    > <body>
    > <form name="cat_list" method="get" action="test.ph p">
    > <table width="100%" border="0" cellpadding="0" cellspacing="0" >
    > <!--DWLayoutTable-->
    > <tr>
    > <td valign="top" class="content1 " style="border-width: 1px 1px 0px
    > 0px;"><!--<input style="width: 100px;" value="{murra31 5}"></td>-->
    >
    > <select name="notify_us er_id[2]" multiple size="4" style="width:
    > 307px;">
    > <option selected value="1"> aaa</option>
    > <option selected value="2"> bbb</option>
    > <option value="3"> ccc</option>
    > <option value="4"> ddd</option>
    >
    > </select>
    > </td>
    >
    > </tr>
    >
    > <tr>
    > <td valign="top" class="content1 " style="border-width: 1px 1px 0px
    > 0px;"><!--<input style="width: 100px;" value="{murra31 5}"></td>-->
    >
    > <select name="notify_us er_id[4]" multiple size="4" style="width:
    > 307px;">
    > <option value="1"> aaa</option>
    > <option value="2"> bbb</option>
    > <option selected value="3"> ccc</option>
    > <option value="4"> ddd</option>
    >
    > </select>
    > </td>
    > </tr>
    >
    > <tr>
    > <td valign="top" class="content1 " style="border-width: 1px 1px 0px
    > 0px;"><!--<input style="width: 100px;" value="{murra31 5}"></td>-->
    >
    > <select name="notify_us er_id[6]" multiple size="4" style="width:
    > 307px;">
    > <option value="1"> aaa</option>
    > <option value="2"> bbb</option>
    > <option value="3"> ccc</option>
    > <option selected value="4"> ddd</option>
    > </select>
    > </td>
    > <tr align="center" valign="middle" >
    > <td height="20" colspan="5" class="content2 "
    > style="border-width: 1px 0px 0px 0px;"><input name="btn_updca ts"
    > type="submit" id="btn_updcats " value="Update">
    > <input name="btn_delca ts" type="submit" id="btn_delcats "
    > value="Delete"> </td>
    > </tr>
    > </tr>
    > <table>
    > </form>
    > </body>
    > </html>
    >
    > PHP -------------------------
    > <?php
    >
    > if (is_array($_GET["notify_user_id "]))
    > {
    >
    > foreach($_GET['notify_user_id '] as $id=>$col_val)
    > {
    > $aRay = array($col_val) ;
    > foreach($aRay as $id2=>$col_val2 )
    > {
    > echo "Box=".$id. ", Id=".$col_val2. "<br>";
    > }
    >
    > }
    > }
    >
    >
    > ?>[/color]

    Change:

    <select name="notify_us er_id[4]"

    to:

    <select name="notify_us er_id[4][]"

    Notice the extra [] after the name. So, on the page that processes the
    form, you'll have $_GET['notify_user_id '][4] and it will be an array:

    foreach($_GET['notify_user_id '][4] as $notify_id) {
    //do something with $notify_id
    }

    Comment

    • murraymiken@yahoo.com

      #3
      Re: Multiple Multiple Select Boxes

      Thanks! ...it looks so obvious now.

      Final update to the example:

      <?php

      if (is_array($_GET["notify_user_id "]))
      {

      foreach($_GET['notify_user_id '] as $id=>$col_val)
      {
      foreach($_GET['notify_user_id '][$id] as $notify_id)
      {
      echo "Box=".$id. ", Id=".$notify_id ."<br>";
      }
      }
      }

      Comment

      Working...