递归问题

kkobebryant 2007-09-10 07:45:09
ProductID ComponentID
10 3
3 2
2 1

如何通过1找到10的ID
function findParent($ComponentID)
{
$sql="SELECT productID FROM product_components WHERE componentID='$ComponentID'";
$result=mysql_query($sql) or die("error:$sql");
if($row=mysql_fetch_array($result))
{
$productID=findParent($row[productID]);
}

return $productID;
}

怎么返回的是2

...全文
86 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
hejunbin 2007-09-10
  • 打赏
  • 举报
回复
$productID = 0;
function findParent($ComponentID)
{
global $productID;

$sql="SELECT productID FROM product_components WHERE componentID='$ComponentID'";
$result=mysql_query($sql) or die("error:$sql");
if($row=mysql_fetch_array($result))
{
$productID=findParent($row[productID]);
}
}

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧