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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.