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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:55:23+00:00 2026-05-24T19:55:23+00:00

I have a table that is editable and sortable . The table has 2

  • 0

I have a table that is editable and sortable. The table has 2 type types of items parents and children. I would like the user to be able to switch between the two and drag between the two, while updating the order. The database table is similar to the following.

+-------------------------------------------------------+-----------+
|id | userid  | item            | parent | item order   | parent_id |
+-------------------------------------------------------+-----------+
|23 | 5       | cheese burger   |false   |     2        |    128    |
+-------------------------------------------------------+-----------+
|128| 5       | Burgers         |True    |     0        |    0      |
+-------------------------------------------------------+-----------+
|10 | 5       | Hamburger       |false   |     1        |    128    |
+-------------------------------------------------------+-----------+
|25 | 5       | steak burger    |false   |     3        |    128    |
+-------------------------------------------------------+-----------+
|90 | 5       | fish   burger   |false   |     4        |    128    |
+-------------------------------------------------------+-----------+
|29 | 5       | fries           |True    |     5        |     0     |
+-------------------------------------------------------+-----------+
|22 | 5       | cheese Fries    |false   |     6        |     29    |
+-------------------------------------------------------+-----------+
|987| 5       | french fries    |false   |     7        |     29    |
+-------------------------------------------------------+-----------+

This will give me a menu like so….

BURGERS
Hamburger
Cheese burger
Steak burger
Fish burger
FRIES
Cheese fries
French fries

Upper case denoting a header*

I can get the order correct, no problem. My script POST‘s an array of the item order.

 Array
 (
   [0] => 128
   [1] => 10
   [2] => 23
   [3] => 25
   [4] => 90
   [5] => 29
   [6] => 22
   [7] => 987
)

Then I update the DB to reflect this, similar to this…

 UPDATE menu SET item_order = '0' WHERE item = '128'
 UPDATE menu SET item_order = '1' WHERE item = '10'
 UPDATE menu SET item_order = '2' WHERE item = '23'
 UPDATE menu SET item_order = '3' WHERE item = '25'
 UPDATE menu SET item_order = '4' WHERE item = '90'
 UPDATE menu SET item_order = '5' WHERE item = '29'
 UPDATE menu SET item_order = '6' WHERE item = '22'
 UPDATE menu SET item_order = '7' WHERE item = '987'

where I am stumbling is getting the parent id right. I have tried all sorts of crazy methods , finding the parent ID then doing a < > sort of thing but nothing seems to get it consistently right. You could drag a header around and this will screw up the children. i.e all the children will adopt the dragged header. How would you approach this? The above update happens when ever a new item is added or an item is dragged.

EDIT

This seems to work……

 $order = "SELECT itemOrder, itemId, header from menuItems && user = $user order by itemOrder"; 
    $order_query = mysql_query($order);
    while($order_result = mysql_fetch_array($order_query))
        {
        $parent = $order_result['header'];
        if ($parent == 'true')
            {
            $current_parent = $order_result['itemId'];  
            }   
            $item_id = $order_result['item_id'];
            $parent_update = "UPDATE menuItems SET parent = '$current_parent' WHERE itemId = $itemId";
          mysql_query($parent_update);
  • 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-24T19:55:24+00:00Added an answer on May 24, 2026 at 7:55 pm

    Since a menu will probably not be a hierarchical structure, I wonder if it wouldn’t be easier to have two tables, one containing the headers and the other containing the items.

    It won’t matter much for this solution, though.

    About the parentid:

    Assuming each item that isn’t a parent itself should have a parent, you could just loop through all items in their posted order and apply this (pseudo code) logic:

    $parentId = null;
    
    loop through items:
      if item->type == header:
         set $parentId to item->id
         update sort order
      else (item is.. well, item)
         check if $parentId !== null. Fail otherwise (item above first header)
         update sort order and parentId
    
    • 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 redundant data and I'm trying to identify all
I have a table that has an insert trigger on it. If I insert
I have a table that looks like that: The rows are sorted by CLNDR_DATE
I have a Core Data backed table view, that show a list of editable
For my iPhone app, I have an editable (for delete) table view. I'd like
I have a MySQL database that has a few very simple tables. I would
I would like to have the editor in my editable JTables select all text
I have an NSTableView that has one column of editable fields. Cell editing works
I have table that I insert data with following query (from c# code): INSERT
I have table that contain date and time field. id|date|time ========= 1|01/01/2001|10:45 2|01/02/2002|11:45 3|01/03/2003|12:45

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.