Hello,
I've got a website where people can create a table of an unknown length containing two columns, word_1
and word_2
, 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 <input/>
-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:
[word_1 ] [word_2 ]
1. [foo ] [bar ]
2. [something ] [more ]
3. [another ] [row ]
...
600. [another_value ] [blabla ]
601. [last ] [row ]
And then someone decides to edit it:
1. [foo ] [bar ]
2. [changed_val ] [more ]
...
234. [another_change] [changed_value]
...
600. deleted
601. [last ] [row ]
602. [new_row ] [new_value ]
I think my HTML-code will look like the following:
<table>
<tr>
<td>
<input type="hidden" name="row[0][id]" value="id-2" />
<input type="text" name="row[0][word_1]" value="value_1" />
</td>
<td>
<input type="text" name="row[0][word_2]" value="value_2" />
</td>
<td>
<img src="img.gif" onclick="delete_row()" />
</td>
</tr>
<tr>
<td>
<input type="hidden" name="row[1][id]" value="id-5" />
<input type="text" name="row[1][word_1]" value="value_1" />
</td>
<td>
<input type="text" name="row[1][word_2]" value="value_2" />
</td>
<td>
<img src="img.gif" onclick="delete_row()" />
</td>
</tr>
</table>
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.