递归函数不';在php中,第二次调用后不执行
我正在开发一个自动化项目管理过程的web应用程序。 我定义了一个递归函数不';在php中,第二次调用后不执行,php,recursion,Php,Recursion,我正在开发一个自动化项目管理过程的web应用程序。 我定义了一个task\u节点类,它代表项目中的任务。 completePath函数根据序列关系完成从当前任务$tNode到任务结束的项目路径。 我的问题是执行在第一次调用completePath后停止。 这是我的密码: private function completePath($tNode,$counter) { // getting data from DB works properly echo '<br>c
task\u节点
类,它代表项目中的任务。
completePath
函数根据序列关系完成从当前任务$tNode
到任务结束的项目路径。
我的问题是执行在第一次调用completePath
后停止。
这是我的密码:
private function completePath($tNode,$counter)
{
// getting data from DB works properly
echo '<br>counter:'.$counter.' <br>task name:'.$tNode->task_name;
$helper=new MySQLHelper();
//getting initial tasks
$cond=" t2.source_task_id='$tNode->task_id'
And t2.relation_type='sequence'
AND t1.task_id=t2.target_task_id";
$tables="tasks t1 , tasks_relations t2";
$nextTask=$helper->getData($tables,'t1.task_id,t1.task_name,t1.task_duration',$cond);
if(mysql_num_rows($nextTask)!=0) // stopping condition
{
$row=mysql_fetch_array($nextTask);
$tNode->nextTask=new Task_Node($row['task_id'],$row['task_name'],$row['task_duration']);
completePath($tNode->nextTask,++$counter);// execution stopped here
}
}
private函数completePath($tNode,$counter)
{
//从数据库获取数据工作正常
回显'
计数器:'.$counter.'
任务名称:'.$t节点->任务名称;
$helper=新的MySQLHelper();
//获取初始任务
$cond=“t2.source\u task\u id=”$tNode->task\u id'
和t2.关系_type='sequence'
t1.任务id=t2.目标任务id”;
$tables=“任务t1,任务\关系t2”;
$nextTask=$helper->getData($tables,'t1.task\u id,t1.task\u name,t1.task\u duration',$cond);
if(mysql_num_rows($nextTask)!=0)//停止条件
{
$row=mysql\u fetch\u数组($nextTask);
$tNode->nextTask=新任务节点($row['Task\u id'],$row['Task\u name'],$row['Task\u duration']);
completePath($tNode->nextTask,++$counter);//执行在此处停止
}
}
有什么想法吗??谢谢你使用
sizeof($nextTask)
或
代替
mysql_num_rows($nextTask).
因为mysql_num_rows()从结果集中检索行数 根据您提供的信息,您应该循环资源结果:
if(mysql_num_rows($nextTask)>0) // stopping condition
{
while($row=mysql_fetch_array($nextTask,MYSQL_ASSOC)){ // loop through the result set
$tNode->nextTask=new Task_Node($row['task_id'],$row['task_name'],$row['task_duration']);
completePath($tNode->nextTask,++$counter);// execution stopped here
}
}
mysql\u fetch\u array
返回一个数组,该数组对应于获取的行,并将内部数据指针向前移动
还请注意,php 5.5中不推荐使用mysql_*函数。请尝试改用
mysqli
。对不起,我没有告诉您我的方法$helper->getData()
返回一个结果集。。!!您的助手返回什么结果集?
if(mysql_num_rows($nextTask)>0) // stopping condition
{
while($row=mysql_fetch_array($nextTask,MYSQL_ASSOC)){ // loop through the result set
$tNode->nextTask=new Task_Node($row['task_id'],$row['task_name'],$row['task_duration']);
completePath($tNode->nextTask,++$counter);// execution stopped here
}
}