No the code from the first page doesn't actually work! I can't understand how people can write these articles without testing the code that they are displaying! Its a good subject but ruined because you can't get past the first page!!
Mr Chocolate use this code:
dB code (need to ensure you use NOT NULL for parent)
Code:
drop database heir;
create database heir;
use heir;
create table tree (
parent varchar(100) not null,
title varchar(100)
);
insert into tree set title="Food";
insert into tree set parent = "Food", title="Fruit";
insert into tree set parent = "Fruit", title="Green";
insert into tree set parent = "Green", title="Pear";
insert into tree set parent = "Fruit", title="Red";
insert into tree set parent = "Red", title="Cherry";
insert into tree set parent = "Fruit", title="Yellow";
insert into tree set parent = "Yellow", title="Banana";
insert into tree set parent = "Food", title="Meat";
insert into tree set parent = "Meat", title="Beef";
insert into tree set parent = "Meat", title="Pork";
revised function code
PHP Code:
function display_children($parent, $level) {
// retrieve all children of $parent
$result = mysql_query("SELECT title FROM tree WHERE parent='".$parent."'");
// display each child
while ($row = mysql_fetch_array($result)) {
// indent and display the title of this child
echo str_repeat('& n b s p ; & n b s p ; & n b s p ; ',$level).$row['title']."\n<br>";
// call this function again to display this
// child's children
display_children($row['title'], $level+1);
}
}
display_children('',0);
(I have changed the $result part to say mysql_query not mysql_result)
This will now display what is mentioned in the article..
Rant over I will now continue to read the article, if I spot any other errors I will post them here so others can work it also
Sarah
Edit:
it displays better with the & n b s p ; without the spaces for the display part
Bookmarks