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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:20:19+00:00 2026-06-13T18:20:19+00:00

I have hierarchical data (categories) stored in a mySql database using the nested set

  • 0

I have hierarchical data (categories) stored in a mySql database using the nested set model.

All is working perfectly only I now need the ability to add a property to any node (force_to_top) which will set the node to temporarily force to the top of its siblings, and I’m not 100% sure how to do this without physically changing the lft and rgt values.

When a nodes force_to_top property is turned on I don’t want to store the original lft and rgt values elsewhere, change the lft and rgt values to move the node to the correct position, and then reset their original lft and rgt values once the force_to_top property is removed. I think that’s going to cause massive problems further down the line, plus it seems like a very roundabout way of doing things? (correct me if that’s in fact the simplest way! But I would like to find another, preferably only using sql not updating any values in the db)

I was wondering if it would be possible to somehow manipulate the output of the sql depending on the force_to_top property?

For example if we have the following structure

        Cars
        |
-----------------
|       |       |
Audi    Ford    VW

Which would have the following lft/rgt/force_to_top values:

node    lft    rgt  force_to_top
Cars    1      8    false
Audi    2      3    false
Ford    4      5    false
VW      6      7    false

When we output the child nodes of ‘Cars’, we’d be given:

Audi
Ford
VW

But lets say the node ‘VW’ has its force_to_top property set to true, what I would really need is the output of the child nodes of ‘Cars’ to now be:

VW
Audi
Ford

As I mentioned I’ve thought about storing the original lft and rgt values and resetting them after the force_to_top property is removed. The plus side of not doing it this way is the speed of turning off the force_to_top property, it would mean no data manipulation other than actually setting the force_to_top value to false again and the node would immediately drop back to its original position. And would also mean I don’t need to create a storage area / extra tables / extra fields for the original lft and rgt values of each node.

I’ve also thought about doing this in the php after I’ve fetched the results, but for large data sets that could really slow things down.

I originally had to set the force_to_top nodes to the top of everything, which was very easy, simply ORDER BY force_to_top, lft, however now only forcing to the top of its siblings is a lot more complicated, as the node may be in the centre of a massive hierarchy.

Any suggestions or a point in the right direction would be much appreciated.

  • 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-13T18:20:20+00:00Added an answer on June 13, 2026 at 6:20 pm

    Just in case anyone stumbles here with a similar problem (very unlikely!):

    In the end the only way I could find to achieve this functionality was to store the category’s current parent_id and nearest_sibling_id when its force_to_top value was set to true.

    This way I could move the category to the top of its parent by updating its lft and rgt values, and then when the force_to_top was removed, I could check the nearest_sibling_id still existed, and that it was still within the original parent_id. If so, move the category back next to its nearest_sibling_id; if not, just move the category to the bottom of its original parent_id as we can’t determine where it really was originally positioned as our nearest_sibling_id value is out of date.

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

Sidebar

Related Questions

I have hierarchical data in a nested set model (table:projects): My table (projects): id,
I have a MySQL database holding hierarchical data using the Closure Table method. A
I have hierarchical data stored in the datastore using a model which looks like
I have three level hierarchical data. using the statement below i managed to display
I have a hierarchical data structure (using Entity beans)like say a Book Class which
I'm working on a project where I have some hierarchical data that I want
I have a set of hierarchical data that I'm hoping to get into the
Working with SQL Server 2008 R2. I have a table of hierarchical data, with
I have a php script that takes hierarchical data from a mysql procedure and
I have a Table for categories , which stores Hierarchical Data in the following

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.