$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;
解决方案 »
- PHP 生成图片的代码
- 如果把访问客户端访问的网页保存到指定的目录
- 有人做过PC端的WAP浏览器吗?
- php oracle 如何在短期内做出web application
- php 正则如何匹配“/”,网络上只有匹配“\”的
- 求教:能把对象(或者数据结构)传递到下一页面吗?
- 请问:php里有没有类似于messagebox()这样的函数?
- 是不是PHP要和哪个数据库相连就要用到相对应的DLL 的文件呢?
- 关于fatal error的一点疑问
- Fatal error: Call to a member function fetch_array() on a non-object in 62 line
- 谁用过zend 的svn?
- php环境配置问题
不能用全局变量,只能用局部变量,也不能用:用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;
?>
这个是不是最顶层的,干嘛那么费事?
不过你那好像是递归输出所有的!