Posted by J.O. Aho on 02/01/06 16:02
Leszek wrote:
> I have a form with 5 dropdown lists I want to put all selected values to an
> array called $data[] so i wrote sometthing like this:
>
> for(i=0;i<5;i++){
> echo"<select name=\"\$data[]\">";
> echo"<option value=\"1\">1</option>";
> echo"<option value=\"1\">2</option>";
> echo"<option value=\"1\">3</option>";
> echo"</select>";
> }
>
> So I think this will put all selected values into an array.
> But the problem is that when user submits the form this array goes to $_POST
> array
> And I have no idea how to read a value from an array $data which is into
> array $_POST and use it as a part of "if" statement
$value_from_array=$_POST['$data'];
//for example
if ($value_from_array[0]==5){
// instructions
}
But would be easier you didn't use the $ in the name
for(i=0;i<5;i++){
echo"<select name=\"\data[]\">";
echo"<option value=\"1\">1</option>";
echo"<option value=\"1\">2</option>";
echo"<option value=\"1\">3</option>";
echo"</select>";
}
$value_from_array=$_POST['data'];
if ($value_from_array[0]==5){
// instructions
}
//Aho
Navigation:
[Reply to this message]
|