Display Hierarchical Data MySQL Error

Hi

I’m trying to adapt a function to Display Hierarchical Data I found on sitepoint
The code I got so far is:

[php]

<?php // $parent is the parent of the children we want to see // $level is increased when we go deeper into the tree, // used to display a nice indented tree $link = mysql_connect("localhost", "root", "palhaco"); if (!$link) { die('Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db('testecat', $link); if (!$db_selected) { die ('Can\'t use foo : ' . mysql_error()); } function display_children($parent, $level) { // retrieve all children of $parent $result = mysql_query('SELECT title FROM testcat '. 'WHERE parent="'.$parent.'";'); // display each child while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { // indent and display the title of this child echo str_repeat(' ',$level).$row['title']."\n"; // call this function again to display this // child's children display_children($row['title'], $level+1); } } display_children('',0); ?>[/php]

But the only thing I got is an error message:

"Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in D:\Web Data\testcat.php on line 20 "

Can some one help me please?

Anyone please?

Sponsor our Newsletter | Privacy Policy | Terms of Service