Show & Edit Multiple Rows (MySQL & PHP)
I've got an interesting problem that I just can't seem to think around. So let's say I have a database table with 'id', 'name', and 'email'. I need to list each result out of the database in an HTML table. Simple, just do a foreach loop and show them all, but I need to edit each one; maybe change the name on one of them and an email o开发者_如何转开发n the other, etc, etc. but then when this super big table/form is submitted, how do I process and update each one? No clue if that even makes sense, but any suggestions would be awesome.
Some thoughts:
- Use AJAX to perform the updates in the background (show a "Save" button when a field is changed/focused then send the row's information off to an ajax page for submission)
- Use JavaScript and a hidden field that's changed on one of the fields' focus event in a row to flag that row has a possible modification
- Use good'ol'fashioned iterating and look for deltas.
Save them all to arrays. In the HTML do:
<input name="id[]" />
etc. And then when you go into PHP do:
foreach($_POST['id'] as $key => $poop) { /* INSERT EACH ROW MYSQL HERE, REFERRING TO THE EMAIL AS $_POST['email'][$key] */ }
精彩评论