Как записать результат функции в перменную?
mysql:
CREATE TABLE IF NOT EXISTS `menu` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
`href` varchar(255) NOT NULL,
`pid` int(10) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=cp1251 AUTO_INCREMENT=10 ;
INSERT INTO `menu` (`id`, `name`, `href`, `pid`) VALUES
(1, 'Hello ', 'hello', 0),
(2, 'hi', 'hi', 1),
(3, 'byy', 'byy', 0),
(4, 'quit', 'hello', 1),
(5, 'exit', 'exit', 2),
(8, 'qweqw', 'zxcvbnm', 2),
(9, 'qweqw', '2', 2);
php:
$parts_query = mysql_query("SELECT id, pid, name FROM menu");
if ($parts_query && mysql_num_rows($parts_query) > 0) {
$parts_array = array();
$part_data[0] = 0;
while ($part_data[0] = mysql_fetch_row($parts_query)) {
$part_data[1] = isset($part_data[1]) && $part_data[1] > 0 ? $part_data[1] : 0;
array_push($parts_array, $part_data[0]);
}
mysql_free_result($parts_query);
}
function menu($parts_array, $pid)
{
$result = "";
$this_count = 0;
foreach ($parts_array as $id => $element) {
if ($element[1] == $pid) {
$this_count++;
if ($this_count == 1)
$result .= ("<ul>
");
$result .= ("<li><a href=\"./parts.php?id=" . $element[0] . "\">" . $element[2] . "</a>");
menu($parts_array, $element[0]);
$result .= ("</li>
");
}
}
if ($this_count > 0)
$result .= ("
</ul>");
return $result;
}
$var = menu($parts_array, 0);