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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:14:14+00:00 2026-06-12T10:14:14+00:00

I have a table that has sortable rows. The table is generated from a

  • 0

I have a table that has sortable rows. The table is generated from a mysql database that has a field called “displayorder” that oders the table. When the user drags and drops rows, I want to use AJAX to submit those changes to the database whenever a user drops a row.

Currently, I can see the console.log() output from the success part of the AJAX call, and when i output the data there (order) it looks great, like this:
["order_1=1", "order_2=2", "order_4=3", "order_3=4"]

But according to Firebug, all that’s getting passed in the $_POST is “undeclared”.
How do I access that order variable from my indexpage_order.php file?

I have this jquery code:

    <script>
    $(document).ready(function() {
        var fixHelper = function(e, tr) {
            var $originals = tr.children();
            var $helper = tr.clone();
            $helper.children().each(function(index)
            {
              $(this).width($originals.eq(index).width())
            });
            return $helper;
        };
        var sortable = $("#sort tbody").sortable({
        helper: fixHelper,
        stop: function(event, ui) {
            //create an array with the new order
            order = $(this).find('input').map(function(index, obj) {
                var input = $(obj);
                input.val(index + 1);
                return input.attr('id') + '=' + (index + 1);
            });
            $.ajax({
                    type: 'POST',
                    url: 'indexpage_order.php',
                    data: order,
                error: function() {
                    console.log("Theres an error with AJAX");
                },
                success: function(order) {
                    console.log("Saved.");
                    console.log(order);
                }
            });
            return false;
        }
        });
    });
    </script>

indexpage_order.php contains:

if(isset($_POST) ) {

    while ( list($key, $value) = each($_POST) ) {
        $id = trim($key,'order_'); //trim off order_
        $sqlCommand = 
            "UPDATE indexpage 
             SET displayorder = '".$value."' 
             WHERE id = '".$id."'";
        $query = mysqli_query($myConnection,$sqlCommand) or die (mysqli_error($myConnection));
        $row = mysqli_fetch_array($query);
    }
}
  • 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-12T10:14:15+00:00Added an answer on June 12, 2026 at 10:14 am

    You can simply rewrite the js code that are generating the data for POST.

    order = {}
    $(this).find('input').map(function(index, obj)
      { 
        return order[this.id] = index;
      }
    )
    

    Rest should work in PHP.

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

Sidebar

Related Questions

I have a table that has several fixed rows that contain user controls that
I have a table that has account numbers in (account_num) and user profiles (profile_id).
I have a table that has an AUTO_INCREMENT field. Currently, it is also a
I have a table that has a link field that I would like to
I have table that has date field. When I run a query, I see
I have a table that is editable and sortable . The table has 2
I have a table that has 50 more rows and 3 columns. I want
I have a table that has two datetime columns (one for start time and
I have a table that has duplicate email address, I need to insert just
I have a table that has no primary key, and one cannot be created

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.