Reply to Implementing a tree

Your name:

Reply:


Posted by nospam on 09/16/05 20:55

Hi all,

I'd like to implement a tree of "tags" for a blog I'm writing for fun in PHP.
Here's what a single tag looks like:


CREATE TABLE tags
(
name varchar(30) not null default '',
id_self integer(12) not null primary key,
id_parent integer(10) not null default 0,
);
INSERT INTO tags VALUES ('root of the tree', 0, 0);


Each tag has a name, a unique id to identify itself with and a parent's id,
and all this will be stored in a database, but stored in no particular order.

I'm a little stumped as to how to reconstruct the tree. Part of the problem
is that suppose my first read to the database yeilds:

name = "physics"
id_self = 21
id_parent = 2


but further down in the database, this record exists:

name = "science"
id_self = 2
id_parent = 0

in other words, it's possible that children may be read before parents.


I've noticed that some people have implemented a tree class. Since this is
supposed to be a *fun* project for me, I'd rather write it myself. But I
find myself staring at the keyboard, not knowing how to start.

How can I reconstruct this tree?

Thanks!
Pete

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация