rofavadeka rofavadeka - 1 year ago 58
Javascript Question

jQuery UI Sortable and updating a mysql database

I am doing something wrong and it's driving me nuts because I can't figure it out.
Using jQuery ui sortable to sort the divs on my page. The sorting part works kinda but it does not update the database.

The only thing I can think of is the clear within page, but if I put this on the div it acts not as fluent.


<div id="page">
<div id="listItem_'.$id.'" class="a bunch of random classes">
<div class="handle"></div>
<div id="listItem_'.$id.'" class="this one has some other classes">
<div class="handle"></div>
<div class="clear"></div>
<div id="listItem_'.$id.'" class="a bunch of some other">
<div class="handle"></div>


handle : '.handle',
update : function () {
var order = $('#page').sortable('serialize');



foreach ($_GET['listItem'] as $position => $item){
$sql = "UPDATE table SET position = ".$i." WHERE id = ".$item;
$res = mysql_query($sql);

Gor Gor
Answer Source

Start debugging by placing var_dump('got here'); (or one of the variables) in your PHP script. Use the console in Firebug (which is an add-on) in Firefox to view the output. Step through until you find the spot where it's failing.