Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Multiple Multiple Select Boxes

0 views
Skip to first unread message

murra...@yahoo.com

unread,
Mar 22, 2006, 1:08:53 PM3/22/06
to
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&notify_user_id%5B2%5D=2&notify_user_id%5B4%5D=2&notify_user_id%5B4%5D=3&notify_user_id%5B4%5D=4&notify_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>";
}

}
}


?>

ZeldorBlat

unread,
Mar 22, 2006, 1:41:25 PM3/22/06
to

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
}

murra...@yahoo.com

unread,
Mar 22, 2006, 2:30:46 PM3/22/06
to
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>";
}
}
}

0 new messages