Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8198733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:00:49+00:00 2026-06-07T06:00:49+00:00

I am using jQuery sortable to manipulate image order and write to a DB.

  • 0

I am using jQuery sortable to manipulate image order and write to a DB. That functionality works well.

PHP

 echo "<div class='revisionNum'>";
            echo "<ul id='sortable_" . $count ."'>";

            while($row = mysql_fetch_array($result)) {
                $sortImageName = $row['OrgImageName']; 
                $sortPath = "../data/gallery/" . $galleryID . "/images/album/" . $sortImageName;
                echo "<li class='sortPhotos' id='item_{$row['id']}' >";
                echo '<img class="sortImage" src="'. $sortPath .'"/>';
                echo "<p>" . $sortImageName . "</p>";
                echo "</li>";
            }
            echo "</ul>";
            echo "</div>";

jQuery

//make sortable
    $(".revisionNum").each(
        function(e) {
        num = e + 1;
        $("#sortable_" + num).sortable(
            {stop:function(i) {
                serial = $("#sortable_"  + num).sortable("serialize");
                $.ajax({
                    type: "GET",
                    url: "../albumUploader/queries/sort.php",
                    data: serial
                });
            },
            opacity:1.0,
            //cursor: move
        });    
    });

MYSQL

foreach($_GET['item'] as $key=>$value) {

    mysql_query("   UPDATE galleryimage
                    SET sort = '{$key}'
                    WHERE id = '{$value}'  
                ");

}
The issue is when I have multiple <div class=''revisionNum> i am only grabbing the serial = $("#sortable_" + num) of the last UL if the [.revisionNum], not the actual UL that I am sorting. Thanks for the help on this. Let me know if further clarification is needed.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T06:00:50+00:00Added an answer on June 7, 2026 at 6:00 am

    I am not sure I fully understand your question, but I think you are looking for the following:

    The variable num will change every loop you make in the each-loop. But at the end it will have the value of the last loop. Because num seems to be a global variable you can’t call it in the stop function. Then it will just use the last value it had. The value of the last loop. (Explains your problem)

    To solve this I recommend to change your code to:

    $(".revisionNum").each(
        function(e) {
        $(this).children("ul").sortable(
            {stop:function(i) {
                num = $(this).children("ul").attr("id").replace("sortable_", "");
                serial = $(this).children("ul").sortable("serialize");
                ...
    

    $(this) refers to the $(".revisionNum") you are looping through and it will be remembered, also in the stop function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got 3 UL lists that are using sortable jquery.ui. All works great, but
I using jQuery-UI sortable which works fine. The problem that I am having is
Im using jquery sortable and connected lists that works great. I have two lists,
I'm using the jquery sortable functionality to sort a list of items in my
I'm using jQuery 1.4 and jQuery UI sortable, my problem that i have two
We have a sortable list using JQuery UI Sortable that we are trying to
I'm using the jQuery UI Sortable on DIV which contains DIV tags. Inside of
I am using jQuery UI Sortable widget for implementing drag and drop functionality in
using the JQuery sortable, and trying to send the new order back to my
I'm using jQuery UI sortable plugin to be able to select and sort items.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.