I'm trying to figure a way to update multiple records with a single submit. The project in question is a slideshow. The form page lists all the images in a slideshow, along with their "sort order" - the order in which they'll be displayed. Each "sort order" is a form field, named after the "imgid" of that slide, which initially echoes the order specified elsewhere. So the generated table might look like this:
<form>
<input type="hidden" name="slideshowid" value="4">
<table>
<tr><td>image 1</td><td><input type="text" name="1" value="1"></td></tr>
<tr><td>image 23</td><td><input type="text" name="23" value="2"></td></tr>
<tr><td>image 15</td><td><input type="text" name="15" value="3"></td></tr>
</table>
</form>
and after I edit it might be:
<form>
<input type="hidden" name="slideshowid" value="4">
<table>
<tr><td>image 1</td><td><input type="text" name="1" value="3"></td></tr>
<tr><td>image 23</td><td><input type="text" name="23" value="2"></td></tr>
<tr><td>image 15</td><td><input type="text" name="15" value="1"></td></tr>
</table>
</form>
of course there might be 3 images or 10 or 20
When I click submit, I want it to do this:
mysql_query("UPDATE slideshowimagetable SET sortorder=3 WHERE imgid=1");
mysql_query("UPDATE slideshowimagetable SET sortorder=2 WHERE imgid=23");
mysql_query("UPDATE slideshowimagetable SET sortorder=1 WHERE imgid=15");
so the update has to cycle for as many variables as there are that have a number for a name (all other submitted variables will have non-number names).
It seems like I need to make some kind of array after the submit - first build it from the variables that have numbers as names, then run an update for each element in the array.
I need some guidance on how to construct this.
And - is it a good idea to name variables with numbers? Or should I add a letter in there, in which case I'll have to strip it out before building the array.
Thanks to any who can help me out!