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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:07:34+00:00 2026-06-11T19:07:34+00:00

I have a MySQL database and I am storing user records in the table

  • 0

I have a MySQL database and I am storing user records in the table structure below

User_mst
-------------------
id
user_name
parent_id
left_id
right_id
position       (keyword "left", "right" as string)
node_level

I am storing user records in a binary tree structure, so that it means there is a maximum of 2 child nodes under each node (User).

From this structure, I want to create a function which has

Input:

1.user_id
2.level
3.position

And the Output should be :

Number of Nodes under given user_id on given level and on given position.

So e.g. if the function is like that below

get_nodes(3, 4, 'left');

Then it should return:
There are X number of nodes under User ID 3 on Level 4

I think that I have to build a function that will process recursively though I would like suggestions.

Please help me build this function. Use any programming language such as C, PHP etc.
I am just looking for the logic here.

Here is the SQL for Create Table and some sample Insert statements:

http://paste.ubuntu.com/1218345/

Thanks in advance

  • 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-11T19:07:35+00:00Added an answer on June 11, 2026 at 7:07 pm

    if you are just looking for the logic, then pseudo-C-code should be fine:

    struct NodeStructure
    {
      int ID;
      int leftID;
      int rightID;
      int level;
      ...
    };
    
    int countChildren( int nodeID, int level )
    {
      NodeStructure * node = find( nodeID );
    
      if( node == NULL )
        return 0;
    
      if( node.level == level )
        return 1;
    
      return countChildren( x.leftID, level ) + countChildren( x.rightID, level );
    
    }
    
    NodeStructure * find( int nodeID )
    {
      // SQL CODE:
      // SELECT * FROM User_mst WHERE id = nodeID;
    
      // if( /* node has been found */ )
        // fill NodeStructure
      // else
        // return NULL;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have mysql database structure like below: CREATE TABLE test ( id int(11) NOT
I have a MySQL database where the table was set up to store the
I have a MySQL database table called Participant that looks something like this: (idParticipant)
I have a MySQL database and with a php function i made a table
I have a MySQL database where I am storing information that is entered from
I have the following database -- MYSQL DROP TABLE IF EXISTS Attributes; DROP TABLE
I have a MySQL database in which I am storing a bunch of textual
I have a PHP MySQL database which I will be storing all my information
I have mysql database like this id | code 1 | bok-1 2 |
I have mysql database and I want a software which can draw the database

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.