JavaScript.CoolDev.Com Support Forums
Any questions related to JavaScript menu and JavaScript tree menu by Javascript.CoolDev.Com
| Author |
Message |
Guest
|
Posted: Thu Jul 24, 2003 10:03 am Post subject: PHP and this tree component |
|
|
Well, I purchased the PRO version yesterday and I must say I'm a little bit dissapointed to see DB examples except PHP which is being used all over the world.
Anyway, I've come up with my own script, but I have some problems with it:
| Code: |
function get_tree($parent_id = 0, $indent=0) {
$query = "SELECT id,name FROM cluecms_pages ";
$query .= "WHERE parent_id='$parent_id'";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
echo "\n\t";
for ($a=0;$a<$indent;$a++) echo "\t";
echo "'".$row['name']."', null, null,";
$indentCheck = $indent;
get_tree($row['id'], $indent+1);
}
}
|
The output now is this:
| Code: |
var TREE_NODES = [
'This is the first page!', null, null,
'[new page]', null, null,
'[new page]', null, null,
'[new page]', null, null,
'blah', null, null,
'This is the second page!', null, null,
'Blah', null, null,
'Isn't it?', null, null,
'I am member of blah', null, null,
'[new page]', null, null,
'[new page]', null, null,
'[new page]', null, null,
'[new page]', null, null,
];
|
The problem is: how to I place those brackets? ( [ and ] )
I can place them ALL or NOT, but I cannot do a check and make sure the brackets are in place:
"has node children?"-> do this
"has node no children?" -> do that
Please help! |
|
| Back to top |
|
 |
AlexKunin Developer
Joined: 03 Jan 2003 Posts: 1191
|
Posted: Thu Jul 24, 2003 10:37 pm Post subject: |
|
|
Samples are not included into COOLjsTree PRO package - we provide them by request (you can send one to jssupport@cooldev.com).
Regarding your code.
| Code: |
01. function get_tree($parent_id = 0, $indent=0) {
02. $query = "SELECT id,name FROM cluecms_pages ";
03. $query .= "WHERE parent_id='$parent_id'";
04. $result = mysql_query($query);
05. while ($row = mysql_fetch_array($result)) {
06. echo "\n\t";
07. for ($a=0;$a<$indent;$a++) echo "\t";
08. echo "['".$row['name']."', null, null,";
09. $indentCheck = $indent;
10. get_tree($row['id'], $indent+1);
11. echo "],"
12. }
13.} |
I've added square braket to the line #08, and one more echo statement at the line #11. Code was not checked, but looks like it is correct: COOLjsTree PRO will ignore undefined array elements - spare commas. |
|
| Back to top |
|
 |
|
|