我在for循环中有SQL查询,我想只回复一次这些查询的成功。这是我的代码的一部分
<?php
for($i=0;$i<sizeof($assigned_project_id);$i++){
$sql2="SELECT * FROM assign_task INNER JOIN branch ON assign_task.branch_ID=branch.branch_ID WHERE project_ID=".$assigned_project_id[$i]." AND USER_ID=1";
$query2=mysqli_query($con,$sql2);
if(mysqli_num_rows($query2)>0){
echo" You have Assigned following Reports";
}
while($row2=mysqli_fetch_assoc($query2)){
echo $row2['branch_ID']." ".$row2['branch_name']."<br/>";
}
}
?>
我想只显示一次“您已分配以下报告”。请帮帮我。
答案 0 :(得分:1)
使用如下
<?php
$test =0 ;
for($i=0;$i<sizeof($assigned_project_id);$i++){
$sql2="SELECT * FROM assign_task INNER JOIN branch ON assign_task.branch_ID=branch.branch_ID WHERE project_ID=".$assigned_project_id[$i]." AND USER_ID=1";
$query2=mysqli_query($con,$sql2);
if(mysqli_num_rows($query2)>0){
if($test==0){
echo" You have Assigned following Reports";
$test++;
}
}
while($row2=mysqli_fetch_assoc($query2)){
echo $row2['branch_ID']." ".$row2['branch_name']."<br/>";
}
}
?>