紧急求助,脑筋急转的问题,请大家看一下. if(条件){ 递归}else{ 最后一个节点的另外处理} 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 总归是一个条件啊:文件到尾部了,XML到了最后的关闭标记……总归有个结束的条件吧。 楼上的朋友,我是楼主,我把问题再描述一下(表的结构如下图),如下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); echo $rows["name"] . "<br>"; $nod = $rows["fid"]; get_path($nod); }}get_path(4);运行上面的代码可以输出如下:中国动力男人中国男人男人人问题:我想在递归最后一次的时候做一些动作,比如.输出最后一个name的时候加上六个星号如下:运行上面的代码可以输出如下:中国动力男人中国男人男人人****** function get_path($nod){ $result = mysql_query("select * from test where id = " . $nod); if($n = mysql_num_rows($result)) { $rows = mysql_fetch_array($result); echo $rows["name"] . "<br>"; $nod = $rows["fid"]; if(get_path($nod) == 0) echo '******'; } return $n;}get_path(4); 那你的这个判断条件不是fid==0吗? 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); echo $rows["name"]; $nod = $rows["fid"]; if(get_path($nod)) echo "<br>"; else echo "******<br>"; return true; } return false;}get_path(4); 写错了,可以把<br>放在内容前面输出,最后多一个<br> 这个标题也太忽悠人了吧 呵呵 递归是个特殊的循环 总要有个条件判断停止递归 PHP对递归支持不好 只能递归循环27次 和平台可能有关系 所以另外想办法吧 PHP对递归支持不好 只能递归循环27次 ,哪个和你说的? 通过商品ID获取api淘宝客链接不成功,空白 一个最简单phpExcel导出的例子,麻烦指点一下? 北京地区招网站程序员 怎么解决php中的文字重复问题 问一个php5配置问题 关于php和MYSQL的两个问题! 最新的php中一般缺省都带有zend,那是否可decode 救急呀!各位高手谁用php编过实现在线出题的程序? 请问如何安装GD图形库呀 数组排序问题 php动态生成树形菜单 APACHE 升级问题
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);
echo $rows["name"] . "<br>";
$nod = $rows["fid"];
get_path($nod);
}
}
get_path(4);
运行上面的代码可以输出如下:
中国动力男人
中国男人
男人
人
问题:我想在递归最后一次的时候做一些动作,比如.输出最后一个name的时候加上六个星号如下:
运行上面的代码可以输出如下:
中国动力男人
中国男人
男人
人******
{
$result = mysql_query("select * from test where id = " . $nod);
if($n = mysql_num_rows($result))
{
$rows = mysql_fetch_array($result);
echo $rows["name"] . "<br>";
$nod = $rows["fid"];
if(get_path($nod) == 0) echo '******';
}
return $n;
}
get_path(4);
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);
echo $rows["name"];
$nod = $rows["fid"];
if(get_path($nod))
echo "<br>";
else
echo "******<br>";
return true;
}
return false;
}
get_path(4);