This question has already been answered:
I make a recursive function to display a menu with an indefinite number of ancestors and descendants. Here is the code:
<? mysql_connect("localhost", "root", ""); mysql_select_db("BD"); //$zapros=mysql_query("select * from test where id=0"); //echo ($zapros); function menu($parent, $h) { $h++; $zapros = mysql_query("select * from test where id={$parent}"); while ($row = mysql_fetch_array($rezult)) { echo "{$row['name']}<p>"; $zapros1 = mysql_query("select * from test where key={$row['id']}"); while ($row1 = mysql_fetch_array($zapros1)) { echo " <p>{$row1['name']}<p>"; $p = $row1['id']; menu($p, $h); } } } menu(0, 0); ?>
Database table:
CREATE TABLE `test` ( `ID` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(20) DEFAULT NULL, `key` int(11) DEFAULT NULL, PRIMARY KEY (`ID`), UNIQUE KEY `ID` (`ID`) ) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=cp1251;
As a result, he writes me:
Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\xampplite\htdocs\test.php on line 16
Various manipulations lead nowhere. Tell me, please, what could be the problem?