|
Posted by ZeldorBlat on 03/22/06 20:41
murraymiken@yahoo.com wrote:
> 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_id%5B2%5D=1¬ify_user_id%5B2%5D=2¬ify_user_id%5B4%5D=2¬ify_user_id%5B4%5D=3¬ify_user_id%5B4%5D=4¬ify_user_id%5B6%5D=4&btn_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.php">
> <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="{murra315}"></td>-->
>
> <select name="notify_user_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="{murra315}"></td>-->
>
> <select name="notify_user_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="{murra315}"></td>-->
>
> <select name="notify_user_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_updcats"
> type="submit" id="btn_updcats" value="Update">
> <input name="btn_delcats" 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>";
> }
>
> }
> }
>
>
> ?>
Change:
<select name="notify_user_id[4]"
to:
<select name="notify_user_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
}
Navigation:
[Reply to this message]
|