GPB1983
asked on
php menu in loop
hello,
I am having a problem with a dropdown menu in php, the menu works fine, it displays everything as it should, but it will not pass down any values. the reason there is a $i next to it is because the number of menus must be the same as the counter in the loop, and each menu must have its own name obviously, so I opted for 'firstname$i' where the first menu would be seen as firstname0, 2nd being firstname1 etc.... the [] are there because tjhe user must be able to select multiple options from the menu.
the code section is:
<?
?>
<FORM method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<?
$i = 0;
while ( $i <= 5 ) {
//echo"Firstname: <input type='text' name='firstname$i'[] />";
echo"<select name= 'firstname[$i]'[] size=4 multiple>
<option>Milk</option>
<option>Coffee</option>
<option>Tea</option>
</select>";
$i++;
}
?>
</Select>
<input type=Submit value=pass on>
</form>
<?
$var2 = $_POST['firstname0'];
print_r($var2);
?>
please can someone show me where it is that I am going wrong.
thanks, Gavin
I am having a problem with a dropdown menu in php, the menu works fine, it displays everything as it should, but it will not pass down any values. the reason there is a $i next to it is because the number of menus must be the same as the counter in the loop, and each menu must have its own name obviously, so I opted for 'firstname$i' where the first menu would be seen as firstname0, 2nd being firstname1 etc.... the [] are there because tjhe user must be able to select multiple options from the menu.
the code section is:
<?
?>
<FORM method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<?
$i = 0;
while ( $i <= 5 ) {
//echo"Firstname: <input type='text' name='firstname$i'[] />";
echo"<select name= 'firstname[$i]'[] size=4 multiple>
<option>Milk</option>
<option>Coffee</option>
<option>Tea</option>
</select>";
$i++;
}
?>
</Select>
<input type=Submit value=pass on>
</form>
<?
$var2 = $_POST['firstname0'];
print_r($var2);
?>
please can someone show me where it is that I am going wrong.
thanks, Gavin
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Works for me.....
_POST["firstname"]
Array
(
[0] => Array
(
[0] => milk
[1] => coffee
[2] => tea
)
[2] => Array
(
[0] => milk
[1] => coffee
)
[4] => Array
(
[0] => milk
[1] => tea
)
[5] => Array
(
[0] => coffee
[1] => tea
)
)
_POST["firstname"]
Array
(
[0] => Array
(
[0] => milk
[1] => coffee
[2] => tea
)
[2] => Array
(
[0] => milk
[1] => coffee
)
[4] => Array
(
[0] => milk
[1] => tea
)
[5] => Array
(
[0] => coffee
[1] => tea
)
)
ASKER
hi thanks, yes it does, but what I need it to do is if i choose stuff from menu one then it prints that, if i select stuff from menu 2 then print that, at the moment it prints everything out.
regards, Gavin
regards, Gavin
No - it only prints what is selected. If you look at the above you will see that the array indexes are 0, 2, 3, 4 and 5. Index number 1 is missing because I did not select anything on that menu.
Perhaps I'm missing the point?
Perhaps I'm missing the point?
Actually index 3 is missing as well.
ASKER
Hi, sorry I mis understood, but you are right.
what I was trying to do was to get the contents of menu 0 into
$var2 = $_POST['firstname0'];
$var3 = $_POST['firstname1'];
etc..
sorry I should have explained better.
regards, Gavin
what I was trying to do was to get the contents of menu 0 into
$var2 = $_POST['firstname0'];
$var3 = $_POST['firstname1'];
etc..
sorry I should have explained better.
regards, Gavin
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks mate, I really appreciate all the help, and the detailed explanation! top marks allround mate! thanks,
regards,
Gavin
regards,
Gavin
ASKER
top quality explanations!
ASKER
thanks for the quick reply, but I have already tried that on another example, the code compiles fine, but doesnt work. it doesnt pass anything.
the url for it is:
http://www.gavinbuczko.co.uk/phplooptrial.php
regards, Gavin