Php 如何从循环中获取总行数?
我制作了一个php页面,在其中我想要获得总行数,但它给了我结果零,我如何在php中求和行数,下面是我的代码:Php 如何从循环中获取总行数?,php,Php,我制作了一个php页面,在其中我想要获得总行数,但它给了我结果零,我如何在php中求和行数,下面是我的代码: <? $recepients=0; $count=count($_POST['events']); for($i=0; $i<$count; $i++){ $select="select b.first_name AS first_name,b.last_name AS last_name from buyers b,registrations r where b.bu
<?
$recepients=0;
$count=count($_POST['events']);
for($i=0; $i<$count; $i++){
$select="select b.first_name AS first_name,b.last_name AS last_name from buyers b,registrations r where b.buyer_id=r.buyer_id and r.event_id='".$_POST['events'][$i]."' group by r.buyer_id";
$res = $GLOBALS ['mysqli']->query ($select) or die ($GLOBALS ['mysqli']->error . __LINE__);
$record=mysqli_num_rows($res);
}
echo $recepients+=$record;
?>
尝试添加到循环中
<?
$recepients=0;
$count=count($_POST['events']);
for($i=0; $i<$count; $i++){
$select="select b.first_name AS first_name,b.last_name AS last_name from buyers b,registrations r where b.buyer_id=r.buyer_id and r.event_id='".$_POST['events'][$i]."' group by r.buyer_id";
$res = $GLOBALS ['mysqli']->query ($select) or die ($GLOBALS ['mysqli']->error . __LINE__);
$record=mysqli_num_rows($res);
$recepients = $recepients + $record;
}
echo $recepients;
?>
尝试添加到循环中
<?
$recepients=0;
$count=count($_POST['events']);
for($i=0; $i<$count; $i++){
$select="select b.first_name AS first_name,b.last_name AS last_name from buyers b,registrations r where b.buyer_id=r.buyer_id and r.event_id='".$_POST['events'][$i]."' group by r.buyer_id";
$res = $GLOBALS ['mysqli']->query ($select) or die ($GLOBALS ['mysqli']->error . __LINE__);
$record=mysqli_num_rows($res);
$recepients = $recepients + $record;
}
echo $recepients;
?>
应在循环内进行计算
$recepients = 0;
for($i=0; $i<$count; $i++){
$select="select b.first_name AS first_name,b.last_name AS last_name from buyers b,registrations r where b.buyer_id=r.buyer_id and r.event_id='".$_POST['events'][$i]."' group by r.buyer_id";
$res = $GLOBALS ['mysqli']->query ($select) or die ($GLOBALS ['mysqli']->error . __LINE__);
$record=mysqli_num_rows($res);
$recepients += $record;
}
echo $recepients;
$recepients=0;
对于($i=0;$iquery($select)或die($GLOBALS['mysqli']->错误。\uuuuu行\uuuuu);
$record=mysqli\u num\u行($res);
$recepients+=$record;
}
回音$recepients;
计算应在循环内完成
$recepients = 0;
for($i=0; $i<$count; $i++){
$select="select b.first_name AS first_name,b.last_name AS last_name from buyers b,registrations r where b.buyer_id=r.buyer_id and r.event_id='".$_POST['events'][$i]."' group by r.buyer_id";
$res = $GLOBALS ['mysqli']->query ($select) or die ($GLOBALS ['mysqli']->error . __LINE__);
$record=mysqli_num_rows($res);
$recepients += $record;
}
echo $recepients;
$recepients=0;
对于($i=0;$iquery($select)或die($GLOBALS['mysqli']->错误。\uuuuu行\uuuuu);
$record=mysqli\u num\u行($res);
$recepients+=$record;
}
回音$recepients;
您是否检查了它是否进入循环?并且还调试了$res
。或者您的数据库没有结果是我检查结果显示了您是否检查了它是否进入循环?并且还调试了$res
。或者您的数据库没有结果是我检查结果显示了我认为您还有一行,$recepients+=$record
。将其更新到$recepients
我想您还有一行,$recepients+=$record
。将其更新为$recepients