Updating database sort column using ajax in php -
i,ve got problem in updating database sort column values using ajax in php.my database looks image have sent respectively
i,m using jqueryui plugin sortable method in order sort database rows sort column values after drag div position , drop it; jqueryui script shown below:
$(document).ready(function(e) { $(".sortable").sortable({ appendto: "parent", axis: "x,y", update: function(event, ui) { var data = $(this).sortable('serialize'); $('#show').text(data); $.ajax({ data: data, type: 'post', url: 'index.php?c=gallery&a=ajax' }); } }); });
the ajax.php file contains codes below :
<?php $i = 0; foreach ($_post['item'] $value) { $model=new gallerymodel(); $model->ajax_update($i,$value); $i++; } ?>
in foreach loop; updating process happening through model file below:
<?php class gallerymodel{ public function ajax_update($i,$value){ $model=new gallerymodel(); $model->db->query("update gallery_cat set sort='$i' sort='$value'"); } }
so "problem" when drag div new position , drop below first time;everything goes fine , sort values changed , being updated desired;but when doing second or third time,the sort values being duplicated(look @ image better recognition): image u see,the sort values of , c rows same , refreshing page desired result not happen.i think there wrong foreach loop can't find it.will grateful helping me.
i think problem in front view part each time may append same dive or class before append clear div contents here no view html part
i thought append show div add
$('#show').remove();
before appending
Comments
Post a Comment