473,320 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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:
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.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>";
}

}
}
?>

Mar 22 '06 #1
2 3086

mu*********@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...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
}

Mar 22 '06 #2
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>";
}
}
}

Mar 22 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Forti2ude | last post by:
Hello, I have a simple form... <form> <select name="foo" multiple> <option value="1">one</option> <option value="2">two</option> <option value="3">three</option> </select>
3
by: vgrssrtrs | last post by:
<html> <head> <script language="JavaScript"> <!-- /* *** Multiple dynamic combo boxes *** by Mirko Elviro, 9 Mar 2005 *** ***Please do not remove this comment
3
by: james.dixon | last post by:
Hi I was wondering if anyone else had had this problem before (can't find anything on the web about it). I have three select elements (list boxes - from here on I'll refer to them as 'the...
4
by: teknoshock | last post by:
I have created a page with multiple drop down boxes, all populated with the same options. My problem is, for 12 dropdown boxes and 40 choices per box, I end up with a massive file. Also, if I...
6
by: Dave | last post by:
On my form I have combo boxes. These combo boxes, after updating them, populate respective listboxes that are located below the combo boxes on the same form. I am trying to use a "generate...
2
by: englishman69 | last post by:
Hello, I have been banging my head against this one for a while... Searches online have revealed many different proposals for correcting my issue but none that I can follow! My basic situation...
25
by: bonneylake | last post by:
Hey Everyone, Well i am not sure if my question needs to be here or in coldfusion. If i have my question is in the wrong section i am sorry in advance an will move it to the correct section. ...
6
by: woodey2002 | last post by:
Hi Everyone. Thanks for your time. I am trying to create a search form that will allow users to select criteria from multiple multi select boxes. So far i have managed to achieve a search option...
1
by: woodey2002 | last post by:
Hi Everyone and many thanks for your time.. I am trying to begin access and a bit of VBA i am enjoying it but I have a annoying problem I just can’t get any where on. My databse mostly includes...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.