Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Basically, do this:</p> <p>First, change your items' id format to the underscored format expected by sortable:</p> <pre><code>&lt;li id="image_7884029"&gt;&lt;img ... &lt;li id="image_7379458"&gt;&lt;img ... </code></pre> <p>Then, use sortable's <code>serialize</code> method in its <code>stop</code> event:</p> <pre><code>... // Within your sortable() setup, add the stop event handler: stop:function(event, ui) { $.ajax({ type: "POST", url: path/to/your/ajax/reorder.php, data: $("#images").sortable("serialize") }); } ... </code></pre> <p>When you use <code>$("#images").sortable("serialize")</code>, sortable's <a href="http://docs.jquery.com/UI/Sortable#method-serialize" rel="nofollow">serialize</a> method will go through the children of #images, i.e. all your li elements, and turn all the ids it finds (<code>image_7884029</code>, <code>image_7379458</code>, etc.) into a list of items like <code>image[]=7884029&amp;image[]=7379458...</code>, <em>in the order they now appear in the list, after sorting</em> (because you're calling it from <code>stop()</code>). Basically it works similar to how an array of checkboxes gets sent when posting a form.</p> <p>You can then pick this up in your server-side "reorder.php", to assign new values to your sort_order column:</p> <pre><code>$items = $_POST['image']; if ($items) { foreach($items as $key =&gt; $value) { // Use whatever SQL interface you're using to do // something like this: // UPDATE image_table SET sort_order = $key WHERE image_id = $value } } else { // show_error('No items provided for reordering.'); } </code></pre> <p>And you're done.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload