Reputation: 1598
Please point me in the right direction here Im trying to do the following:
Here is my form
$i=0;//counter
while($row=mysql_fetch_array($result)){
$team1 = $row['team1'];
$team2 = $row['team2'];
$id[$i]= $row['event_id'];
echo'<h3>'.$team1.' VS '.$team2.'</h3>';
echo'<select name="'.$id[$i].'">';
echo'<option value="'.$row['team1'].'">'.$team1.'</option>';
echo'<option value="'.$row['team2'].'">'.$team2.'</option>';
echo'</select>';
$i++;
}//while
Here is my for loop giving error, I suspect problem is in the
$_POST['$id']
...
if(isset($_POST['submit'])){
foreach($_POST[$id] as $eventId => $winner){
echo'<h3>'.$eventId.'</h3>';
}//for loop
}//end isset
Any help will be greatly appreciated
Upvotes: 0
Views: 196
Reputation: 36
You don't know what the event_id values are on the action page, so I think you'll have to query for those again something like:
if(isset($_POST['submit'])){
/* do your query here */
$data = array();
while($row=mysql_fetch_array($result)){
$data[] = $_POST[$row['event_id']];
}
foreach($data as $key => $value){
print_r($_POST[$value]);
echo "<br>";
}
}
Upvotes: 0
Reputation: 2684
$id is defined as an array here$id[$i]= $row['event_id'];
. Arrays can not be used as a key in a foreach array or otherwise.
This is what is causing you an error on this line
foreach($_POST[$id] as $eventId => $winner){ //$id is an array of values
echo'<h3>'.$eventId.'</h3>';
}//for loop
You have to make a second foreach statement for the $id then use the id values in your current foreach statement.
foreach( $id as $key => $val ) {
foreach( $_POST[$val] as $eventId => $winner){
Upvotes: 2