$output = '';
mysql_connect("localhost","root",123456);
mysql_select_db("temp");
mysql_query("set names gbk");
function get_path($nod)
{
$result = mysql_query("select * from test where id = " . $nod);
if(mysql_num_rows($result))
{
$rows = mysql_fetch_array($result);
$output = $rows["name"];
$nod = $rows["fid"];
get_path($nod);
}
}
get_path(4);
echo $output;
mysql_connect("localhost","root",123456);
mysql_select_db("temp");
mysql_query("set names gbk");
function get_path($nod)
{
$result = mysql_query("select * from test where id = " . $nod);
if(mysql_num_rows($result))
{
$rows = mysql_fetch_array($result);
$output = $rows["name"];
$nod = $rows["fid"];
get_path($nod);
}
}
get_path(4);
echo $output;
不能用全局变量,只能用局部变量,也不能用:用if($rows["fid"] == 0)这个条件来判断
哈哈,
<?php
$output = '';
mysql_connect("localhost","root","123456");
mysql_select_db("temp");
mysql_query("set names gbk");
function get_path($nod)
{
$result = mysql_query("select * from test where id = '$nod';");
if(mysql_num_rows($result))
{
$rows = mysql_fetch_array($result);
$output = $rows["name"];
$nod = $rows["fid"];
get_path($nod);
}
return $output;
}
$new = get_path(4);
echo $new;
?>
这个是不是最顶层的,干嘛那么费事?
不过你那好像是递归输出所有的!