The fastest way to update a database table

tankbaja

New Member
I've got a website where people can create a table of an unknown length containing two columns, \[code\]word_1\[/code\] and \[code\]word_2\[/code\], and store this table in a database. It is of course very simple to insert these values into the database by just iterating through the rows.Now someone decides to update some of the values and he goes to the edit-page where he finds all the rows in \[code\]<input/>\[/code\]-fields in a table. What is the fastest way to update these values when he edits the content, adds another row or deletes a row?For example, this is the table after it was created:\[code\] [word_1 ] [word_2 ]1. [foo ] [bar ]2. [something ] [more ]3. [another ] [row ]...600. [another_value ] [blabla ]601. [last ] [row ]\[/code\]And then someone decides to edit it:\[code\]1. [foo ] [bar ]2. [changed_val ] [more ]...234. [another_change] [changed_value]...600. deleted601. [last ] [row ]602. [new_row ] [new_value ]\[/code\]I think my HTML-code will look like the following:\[code\]<table> <tr> <td> <input type="hidden" name="row[0][id]" value="http://stackoverflow.com/questions/1989360/id-2" /> <input type="text" name="row[0][word_1]" value="http://stackoverflow.com/questions/1989360/value_1" /> </td> <td> <input type="text" name="row[0][word_2]" value="http://stackoverflow.com/questions/1989360/value_2" /> </td> <td> <img src="http://stackoverflow.com/questions/1989360/img.gif" onclick="delete_row()" /> </td> </tr> <tr> <td> <input type="hidden" name="row[1][id]" value="http://stackoverflow.com/questions/1989360/id-5" /> <input type="text" name="row[1][word_1]" value="http://stackoverflow.com/questions/1989360/value_1" /> </td> <td> <input type="text" name="row[1][word_2]" value="http://stackoverflow.com/questions/1989360/value_2" /> </td> <td> <img src="http://stackoverflow.com/questions/1989360/img.gif" onclick="delete_row()" /> </td> </tr></table>\[/code\]Is there a better way to update the table than to go trough each of these rows and check with a query if the current row is edited? And what is the best way to see if a row is deleted? I know this data is very easy to store in XML, but I prefer a database so I can link data from other tables and users etc. together.
 
Back
Top