I’m using the following code to allow an administrator to resort a list. Then I want to update my db with this new sort order.
<div id="item_list">
<ul id="sortable">
<?php
$i=1;
foreach ($row_Item as $row){
echo ("<li><span></span><table><tr><td class=\"input_td\">" . $row['item_name'] . "</td><td class=\"input_td_right\">" . $row['program_sort'] . "</td><td class=\"input_td_right\">$" . number_format($row['prog_earnings'],0,".",",") . "</td><td class=\"input_td_right\">" . $i . "</td></tr></table></li>");
$i=$i+1;
}
?>
</ul>
</div>
The items are intitially ordered by the $row[‘program_sort’] value which is calculated by a subroutine. This list then needs to be tweaked by the administrator by moving a few items around in list order.
I don’t understand how to use the jQuery seralize method to extract the new order as it relates to the $row[‘item_name’] in each li. Do I have to use ids for each li, maybe equal to the $row[‘item_name’]? What I need is something like item_name1 =>5, item_name2=>2, item_name3=>4 if the user resorts the list to those positons. Then I can update the db with the new sort order.
I always seem to need a little help when using something new to me in jQuery. Could someone please give me a little help?
Thanks
jQuery serialize() needs form elements, but I can’t see any in your code. You can use an own script to create the sort order object, e.g.:
Also see this example.