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 7428877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:52:44+00:00 2026-05-29T08:52:44+00:00

I know this question has been asked before but the solutions did not work

  • 0

I know this question has been asked before but the solutions did not work for me. I am trying to save the new ordering of items to the database.

I have simplified it very considerably but this is the basic idea of it. I have a form with a sortable list embedded in it.

<form id="itemlist">
    <ul id="itemsort">
       <li id="Item_1">Item<input type="hidden" name="itemid[]" value="itemsRowID01"/></li>
       <li id="Item_2">Item<input type="hidden" name="itemid[]" value="itemsRowID02"/></li>
       <li id="Item_3">Item<input type="hidden" name="itemid[]" value="itemsRowID03"/></li>
       <li id="Item_4">Item<input type="hidden" name="itemid[]" value="itemsRowID04"/></li>
    </ul>
</form>

I have JQuery and JQuery UI Loaded and the The Following code enables the sortable list function and posts the item ids and New sort order to a php script. the “editor” variable is a public variable that is set on load it works fine. The sorting works fine but the neworder value that posts doesn’t seem to change when I re-order the list.

//sorting feature  
    $("#itemsort").live('hover', function() {
        $("#itemsort").sortable({ 
            opacity:.5,
            update : function () {          

                var neworder =  $('#itemsort').sortable('serialize');
                var inputs = serializePost('#itemlist');

                $.post("core/actions.php",{
                   'order': editor,
                   'inputs': inputs,
                   'neworder': neworder},function(){

                       alert("Order saved.", 1);

                });
            } 
        });
    });

On actions.php…

    if(isset($_POST['order'])){

            //set a variable for each post
            $batchid = $_POST['inputs']['itemid'];

            parse_str($_POST['neworder'], $neworder);

            //count the number of entries to be ordered
            $count = count($batchid);        

            //use the count to create an incremental loop for each item to be updated.
            $i=0;
            while ($i <= $count) {

   $query ="UPDATE {$_POST['order']} SET order=$neworder[item][$i] WHERE id=$batchid[$i]";
                ++$i;
            }
        }

I’m not sure why the order I get for each item will not change.

Any Ideas?

-L

  • 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-05-29T08:52:46+00:00Added an answer on May 29, 2026 at 8:52 am
    $("#list").live('hover', function() {
            $("#list").sortable({
    
                update : function () {
    
                    var neworder = new Array();
    
                    $('#list li').each(function() {    
    
                        //get the id
                        var id  = $(this).attr("id");
                        //create an object
                        var obj = {};
                        //insert the id into the object
                        obj[] = id;
                        //push the object into the array
                        neworder.push(obj);
    
                    });
    
                    $.post("pagewhereyouuselist.php",{'neworder': neworder},function(data){});
    
                }
            });
        });
    

    Then in your PHP file, or in this example “pagewhereyouuselist.php”

    $neworderarray = $_POST['neworder'];
    //loop through the list of ids and update your db
    foreach($neworderarray as $order=>$id){    
        //you prob jave a connection already i just added this as an example
        $con = mysql_connect("host","username","password");
    
        if (!$con){
             die('Could not connect: ' . mysql_error());
        }
    
        mysql_select_db("my_db", $con);
    
        mysql_query("UPDATE table SET order = {$order} WHERE id = {$id}");
        mysql_close($con);
    
    }
    

    that should do it
    i didn’t test it as it is an example connection. the actual script I am actually using is more specific to my program this is a simplified version to show the concept

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

Sidebar

Related Questions

I know this question has been asked before but the other solutions didn't work
I know this specific question has been asked before , but I am not
I know this type of question has been asked before, but I could not
I know this question has been asked before, but I ran into a problem.
I know this question has been asked a bit before. But looking around I
I know this question has been asked here before, but I don't think those
I know this sort of question has been asked before , but I still
I know this question has been asked here a few times before. But i
I know this question has been asked before, but none of the previous answers
I know this question has been asked before, but no one has given any

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.