Jquery append/Remove and saving to database

KamiKaZ

New Member
I was wondering if anyone could take a look at this code and help me come up with a better way to do this if there is one.I am using jQuery append/remove to add and remove list items. My code first selects any existing rows from the db and displays those in the list, and then the user can add or remove any elements from the list.I have a database structure similar to this:\[code\]object_id element_id auto order 1 1 0 2 1 2 0 1 1 3 1 3\[/code\]After users have finished appending/remove I will be left with html code similar to this:\[code\]<ul id="element-list" class="ui-sortable"><li><label for="element">Element Description</label><input type="hidden" value="http://stackoverflow.com/questions/3814835/1" name="element[1][id]"><input type="checkbox" value="" name="element[1][auto]"></li><li><label for="element">Element Description</label><input type="hidden" value="http://stackoverflow.com/questions/3814835/2" name="element[2][id]"><input type="checkbox" value="" name="element[2][auto]"></li></ul>\[/code\]As users can add and remove elements including rows which exist in the database I am puzzled about how it is best to save these changes in the database. Currently I am deleting all corresponding rows then inserting new rows inside a loop as follows:\[code\]foreach($_POST['element'] as $element){$auto = (isset($element["auto"])) ? 1 : 0;$query="INSERT INTO $table (object_id, element_id, auto) VALUES ('".$object_id."', '".$element["id"]."', '".$auto."') ";}\[/code\]I am wondering if there is a more efficient way to do this than deleting all rows then inserting new ones?Any input would be appreciated.ThanksPaul
 
Back
Top