Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery sortable - PHP
    text
    copied!<p>I am using the jQuery sortable() to order images in a DB. The HTML is as follows.</p> <pre><code>&lt;h2&gt;Revision 1&lt;/h2&gt; &lt;ul class='sortable'&gt; &lt;li class='sortPhotos' id='item_249745' &gt; &lt;img src="../data/gallery/13387/images/album/1650519801.jpg"/&gt; &lt;p&gt;1650519801.jpg&lt;/p&gt; &lt;/li&gt; &lt;li class='sortPhotos' id='item_249744' &gt; &lt;img src="../data/gallery/13387/images/album/704633205.jpg"/&gt; &lt;p&gt;704633205.jpg&lt;/p&gt; &lt;/li&gt; &lt;/ul&gt; &lt;h3&gt;Revision 2&lt;/h3&gt; &lt;ul class='sortable'&gt; &lt;li class='sortPhotos' id='item_518811' &gt; &lt;img src="../data/gallery/13387/images/album/001.jpg"/&gt; &lt;p&gt;001.jpg&lt;/p&gt; &lt;/li&gt; &lt;li class='sortPhotos' id='item_518812' &gt; &lt;img src="../data/gallery/13387/images/album/003.jpg"/&gt; &lt;p&gt;003.jpg&lt;/p&gt; &lt;/li &lt;/ul&gt; </code></pre> <p><strong>The JS</strong></p> <pre><code>&lt;script&gt; $(".sortable").sortable({stop:function(i) { $.ajax({ type: "GET", url: "../albumUploader/queries/sort.php", data: $(".sortable").sortable("serialize") }); }, opacity:1.0 }); &lt;/script&gt; </code></pre> <p><strong>And finally the SQL</strong></p> <pre><code>foreach($_GET['item'] as $key=&gt;$value) { mysql_query(" UPDATE galleryimage SET sort = '{$key}' WHERE id = '{$value}' "); } </code></pre> <p>The issue with the above example -- the first revision is the only revision that is actually sorting in the DB. The other revision(s) are not. It does appear from monitoring the network in Chrome web developer extension that both lists are sending to the DB, but the second is not writing. Any ideas on this one?</p>
 

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