ParentID looks for id of zero

I have two joined tables clubs and members. I would like to create a simpletree of
Club1 Name
Member1
Member2
Club2 Name
Member1
Member2
etc.

I have used the $tree->render_sql method but I get an error because the parentid is compared to 0 and the id in the tables does not contain 0.
The log contains

SELECT members.club_id, clubs.id, clubs.name, members.last_name FROM clubs
LEFT OUTER JOIN members ON clubs.id = members.club_id WHERE clubs.id = ‘0’

I am very new at this. Any help would be appreciated.

Hi,

by default to root id is 0. And it is set in the 4th parameter of the tree constructor:

tree=new dhtmlXTreeObject(“treeboxbox_tree”,“100%”,“100%”,0);

If the root id is different, you need to set in the constructor:

tree=new dhtmlXTreeObject(“treeboxbox_tree”,“100%”,“100%”,“custom_id”);

and pass it to the connector script with the “id” parameter:

tree.loadXML(“tree.php?id=custom_id”);

Thank you. I understand the concept I think but I need details on implementation. Is there an example that would use this method.

Specifically how is custom_Id initialized. When I pass a 1 I get this in the log.

SELECT members.club_id, clubs.id, clubs.name FROM clubs
LEFT OUTER JOIN members ON clubs.id = members.club_id WHERE clubs.id = ‘1’

Undefined index: clubs.name at C:\Users\jgitta\Documents\Programming\rotarymembership\Tree\codebase\tree_connector.php line 131

Again I am trying to make a tree of joined tables with Clubs as the parent and Members as the Child elements.
A working example would be of great help

Here is the article:

docs.dhtmlx.com/doku.php?id=dhtm … iting_data

The sample in the connector package:
samples/tree/01_basic.html

Thank you I have looked over the article have no luck in setting up the grid. I still get an invalid index error. Do you have an example with data that would show how this is done?

Hello,

unfortunately, we have not ready samples with several tables. Make sure that render_sql is corretly defined. It seems the there is not parent field in your tables, as teams.team_id and project_team.team_id are item ids. If there were a parent field in the clubs table, you could do the following:

$tree->render_sql(“SELECT members.club_id, clubs.id, clubs.name,clubs.parent_field FROM clubs
LEFT OUTER JOIN members ON clubs.id = members.club_id”,“id”,“name”,"",“parent_field”);

Thanks for the reply.

Could you give me an example or what form the parentID would take?

For example I have

Clubs Table
id
name

Members table
id
last_name
first_name
club_id

Right now I have the id of the clubs table and a clubs_id in the members table for use as a join field. Do I need to add a field in the members table or the clubs table.

This question is already answered at support.dhtmlx.com Try the solution provided there.

Hi,

I understand everything and it works, the funny thing is, that passing id=1 means that my “real” root node is not shown anymore:

e.g. (Default id=0)

(1) Company
(2) - Department 1
(3) - Department 2

now (id = 1)
(2) Department 1
(3) Department 2

So, by passing the startID 1, the node with the ID = 1 is not shown anymore :frowning:
How can I solve this issue?

Thx and best regards! Phil

Hi,

root node is not shown - please check tree samples. If tree structure contains 3 levels: company->department->member, you need to add the new level to TreeMultitableConnector.

Hi, I think this will not solve my problem… I have the professional version of dhtmlxtree;) and I use the render_sql-function… As the levels are dynamically, it´s not possible, to set max level… and an other problem is, that based upon user rights everybody has different startpoints…

As the levels are dynamically

maxLevel allows to control child=“1” attribute automatically. For example if you have set maxLevel 2 and there are only 2 levels in tree (correct maxLevel in this case is 1), the second level will be rendered as folder (with +).

You may set any maxLevel, but in this case you’ll have to set onBeforeRender event and manage child attribute manually:

docs.dhtmlx.com/doku.php?id=dhtm … forerender
docs.dhtmlx.com/doku.php?id=dhtm … re_loading