Jump to content

2 dimensional POST array - help needed


plastik77

Recommended Posts

Hi, I'm struggling with a problem on a form where i'm allowing the user to update multiple records at the one time. My mind has gone completely blank as to how i retrieve the form data correctly -

 

the form is as follows:

echo "<table border = 1 cellspacing = 1><tr><th>Date (dd/mm/yy)</th><th>Team</th><th>Opposition</th><th>Venue</th><th>Kick off</th><th>Arrangements</th></tr>";
				for ($i=0; $i<$numrows; $i++) {
					//manipulate the date returned from mysql
					$row = $connector->fetchArray($result);
					$id = $row['id'];
					echo "<tr>";
					echo "<td><input type='text' name='date[$id]' class='date' value='".$row['date']."'</td>
					<td><input type='text' name='team[$id]'  class='team' value='".$row['team']."'</td>
					<td><input type='text' name='opposition[$id]'  class='opposition' value='".$row['opposition']."'</td>
					<td><input type='text' name='venue[$id]' class='venue' value='".$row['venue']."'</td>
					<td><input type='text' name='kick_off[$id]' class='kick_off' value='".$row['kick_off']."'</td>
					<td><input type='text' name='arrangements[$id]' class='arrangements' value='".$row['arrangements']."'</td>
					</td><td><a href='delete_fixture.php?delete_id=".$row['id']."'>Delete</a></td>";
					echo "</tr>";
				}		
				echo "</table>";
				echo "<input type='submit' class='submit' name='update_this_weeks' value='Update'/>";

 

I want to be able to loop through these fields and update the records in the database, but i'm not sure of the syntax i should be using. Can anyone help at all?

 

I know I should be using foreach in something like the following:

if (isset($_POST['update_this_weeks'])) {
	//loop through each set of records
	foreach($_POST as $k => $value) { 
		echo $k; //just testing here, but this doesn't work for me
}
}

Link to comment
https://forums.phpfreaks.com/topic/88575-2-dimensional-post-array-help-needed/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.