Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Adjancey Tree Confusion

by TedPride (Priest)
on Apr 08, 2006 at 05:46 UTC ( [id://542016]=note: print w/replies, xml ) Need Help??


in reply to Adjacency Tree Confusion

No matter what kind of table you're setting up, you should always have a field for record ID (PRIMARY KEY AUTO INCREMENT or whatever). Since records from SELECT are returned in order of the PRIMARY KEY (the same order in which they were created), and you're pushing them into arrays, proper order should be retained for children of the same parent. If instead you want them in a different order, like say ordered by last modified time instead of created time, then just use an ORDER BY in your query. Children of the same parent should now be ordered by modified time, without having to change the basic algorithm. Incidently, here's a modified version of the function for assigning everything to an array:
my @all; construct($_, \@all) for @threads; print "$_->{'id'} $_->{'title'}\n" for @all; sub construct { my ($p, $all) = @_; push @$all, $p; construct($_, $all) for @{$p->{'children'}}; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://542016]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2024-03-29 00:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found