By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,876 Members | 1,206 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,876 IT Pros & Developers. It's quick & easy.

rather noob trouble w/ tree expanding

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.