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
if you are just looking for the logic, then pseudo-C-code should be fine: