473,508 Members | 2,441 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

rather noob trouble w/ tree expanding

the thing is that descentant branches i dont want to expand do expand.
$id variable contains an array of branches i want the program to go
through (alcohol's id -beer id etc)

function tree_list($parent, $level,$id) {
// retrieve all children of $parent

$result = mysql_query('SELECT cname,cid FROM kategorie '.
'WHERE parent="'.$parent.'";');
while ($row = mysql_fetch_array($result)) {
echo str_repeat('&nbsp;&nbsp;',$level).$row['cname']."<br/>\n";

if ($row['cid']==$id[$level])
$this->tree_vypis($row['cid'], $level+1);
}
}
Mar 10 '07 #1
5 1603
Milan Krejci kirjoitti:
the thing is that descentant branches i dont want to expand do expand.
$id variable contains an array of branches i want the program to go
through (alcohol's id -beer id etc)

function tree_list($parent, $level,$id) {
// retrieve all children of $parent

$result = mysql_query('SELECT cname,cid FROM kategorie '.
'WHERE parent="'.$parent.'";');
while ($row = mysql_fetch_array($result)) {
echo str_repeat('&nbsp;&nbsp;',$level).$row['cname']."<br/>\n";

if ($row['cid']==$id[$level])
$this->tree_vypis($row['cid'], $level+1);
}
}
Sorry but I don't understand what the problem is. There seems to be some
sort of recursive hierarchy tree structure involved but that's all I
get. Also it would be nice to know what the method tree_vypis does. Try
reformatting the question. What exactly is the _problem_?

Btw: A noob using classes and recursion? A case of cut'n'paste coding?

--
"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
sp**@outolempi.net | Gedoon-S @ IRCnet | rot13(xv***@bhgbyrzcv.arg)
Mar 10 '07 #2
Rik
Kimmo Laine <sp**@outolempi.netwrote:
Milan Krejci kirjoitti:
>the thing is that descentant branches i dont want to expand do expand..
$id variable contains an array of branches i want the program to go
through (alcohol's id -beer id etc)
function tree_list($parent, $level,$id) {
// retrieve all children of $parent
$result = mysql_query('SELECT cname,cid FROM kategorie '.
'WHERE parent="'.$parent.'";');
while ($row = mysql_fetch_array($result)) {
echo str_repeat('&nbsp;&nbsp;',$level).$row['cname']."<br/>\n";
if ($row['cid']==$id[$level])
$this->tree_vypis($row['cid'], $level+1);
}
}

Sorry but I don't understand what the problem is. There seems to be some
sort of recursive hierarchy tree structure involved but that's all I
get. Also it would be nice to know what the method tree_vypis does.
Also, what this mysterious $id does, and why it is not fed down the
recursion like the rest.
Btw: A noob using classes and recursion? A case of cut'n'paste coding?
Nah, I made (local test-)server crashing recursions and classes the first
week I used PHP :P
--
Rik Wasmus
Posted on Usenet, not any forum you might see this in.
Ask Smart Questions: http://tinyurl.com/anel
Mar 10 '07 #3
Rik
Rik <lu************@hotmail.comwrote:
>Milan Krejci kirjoitti:
>>$id variable contains an array of branches i want the program to go
through (alcohol's id -beer id etc)
Also, what this mysterious $id does, and why it is not fed down the
recursion like the rest.
D'OH

But it surely indicates the problem: $id should be in the recursion too.
Assuming you translated your function's name and actually tree_vypis ==
tree_list:

$trail = array(
1 ='<drink_id>',
2 ='<alcohol_id>',
3 ='<beer_id>',
4 ='<grolsch_id>'); //Grolsch!

function tree_list($parent=0,$level=1,$trail=array()) {
// retrieve all children of $parent
$result = mysql_query("SELECT cname,cid FROM kategorie
WHERE parent='{$parent}');
while ($row = mysql_fetch_assoc($result)) {
echo str_repeat('&nbsp;&nbsp;',$level).$row['cname']."<br/>\n";
if ($row['cid'] == $id[$level]) tree_list($row['cid'],
$level+1,$trail);
}
}

tree_list(0,1,$trail);

Then again, the previous posted function would result in _less_ expansion
instead of more... (And a notice that $id did not exist, and certainly was
no array). Seems like someone did not post the exact function as actually
used?

--
Rik Wasmus
Posted on Usenet, not any forum you might see this in.
Ask Smart Questions: http://tinyurl.com/anel
Mar 10 '07 #4
rdw
Kimmo Laine wrote:
Milan Krejci kirjoitti:
>the thing is that descentant branches i dont want to expand do expand.
$id variable contains an array of branches i want the program to go
through (alcohol's id -beer id etc)

function tree_list($parent, $level,$id) {
// retrieve all children of $parent

$result = mysql_query('SELECT cname,cid FROM kategorie '.
'WHERE parent="'.$parent.'";');
while ($row = mysql_fetch_array($result)) {
echo str_repeat('&nbsp;&nbsp;',$level).$row['cname']."<br/>\n";

if ($row['cid']==$id[$level])
$this->tree_vypis($row['cid'], $level+1);
}
}

Sorry but I don't understand what the problem is. There seems to be some
sort of recursive hierarchy tree structure involved but that's all I
get. Also it would be nice to know what the method tree_vypis does. Try
reformatting the question. What exactly is the _problem_?

Btw: A noob using classes and recursion? A case of cut'n'paste coding?
i may have been using linux and php for a couple of years. when i cut n
pasted the code i realized it wasnt almost different from what i wrote
>
the program expands tree from a typical (category name, category id and
category parent) mysql db. the trouble is that i get
Alkohol
Beer
f
e
Likery
Bozkov
Citrus
Fernet
Vodka
Chipsy
Noviny

when i wanted the Beer branch stay collapsed. i wanted only to list
Likery->Bozkov.

Mar 11 '07 #5
rdw
Rik wrote:
Rik <lu************@hotmail.comwrote:
>>Milan Krejci kirjoitti:
$id variable contains an array of branches i want the program to go
through (alcohol's id -beer id etc)
>Also, what this mysterious $id does, and why it is not fed down the
recursion like the rest.

D'OH

But it surely indicates the problem: $id should be in the recursion too.
Assuming you translated your function's name and actually tree_vypis ==
tree_list:

$trail = array(
1 ='<drink_id>',
2 ='<alcohol_id>',
3 ='<beer_id>',
4 ='<grolsch_id>'); //Grolsch!

function tree_list($parent=0,$level=1,$trail=array()) {
// retrieve all children of $parent
$result = mysql_query("SELECT cname,cid FROM kategorie
WHERE parent='{$parent}');
while ($row = mysql_fetch_assoc($result)) {
echo str_repeat('&nbsp;&nbsp;',$level).$row['cname']."<br/>\n";
if ($row['cid'] == $id[$level]) tree_list($row['cid'],
$level+1,$trail);
}
}

tree_list(0,1,$trail);

Then again, the previous posted function would result in _less_
expansion instead of more... (And a notice that $id did not exist, and
certainly was no array). Seems like someone did not post the exact
function as actually used?

--Rik Wasmus
Posted on Usenet, not any forum you might see this in.
Ask Smart Questions: http://tinyurl.com/anel
THANK you how could i overlook 2 stupid mistakes... typical :)
Mar 11 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2671
by: erikd | last post by:
I'm using an expanding tree menu based on the design from Dieter Bungers GMD (www.gmd.de) and infovation (www.infovation.de) named displayToc.js. The problem is that the script isn't working...
19
6744
by: Christian Fowler | last post by:
I have a VERY LARGE pile of geographic data that I am importing into a database (db of choice is postgres, though may hop to oracle if necessary). The data is strictly hierarchical - each node has...
4
1725
by: Steve | last post by:
How do I prevent a tree control from scrolling when an item is selected? I have tried handling the WM_VSCROLL message but that only works when the scroll occurs from the scroll bar. When the tree...
4
11944
by: James L | last post by:
I have a tree view with a root, 3 noodes(1,2,3) each having one sub node. I drill down to a node. I get the path by saying treeView1.selectedNode.fullpath and assign it to a variable. If I...
1
3839
by: smilecry | last post by:
I am trying to create a tree table (javascript code was adopted from online source) but the rowspan in td tag does not work well when I toggle the rows. Here is the sample code, notice the row "4"...
1
2261
by: hmoundekar | last post by:
actually i want to generate a tree structure on client side, the application is simple web based, and need to display the data extracted from the database to client in tree structure. but the problem...
2
1315
by: Tom | last post by:
My older system: Win2k, VS2005(Academic), .Net 2.0 SP1. Windows.Forms Application: Two splitter panels, a TreeView (named: "tree") in one panel populated with directory name nodes. Logic for...
1
1795
by: Joe Chiang | last post by:
I've got a AJAX Tree Node working with MySQL database. What it does is, Expanding Nodes until there are no Children Nodes in the Database. Now, I am trying to Write a Java Script to Create a...
0
7223
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7321
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5623
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5045
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3191
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1544
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.