0

如果我有两个循环,我想知道如何计算结果!:

$select = "SELECT X FROM Y"

$result = mysql_query($select,$link);

$total = mysql_num_rows($result);

while($row = mysql_fetch_array($result)) {

    $Name = $row['X'];
    $select2 = "SELECT id FROM `".$Name."` ";
    $result2 = mysql_query($select2,$link) or die ('Erreur : '.mysql_error() );
    $total2 = mysql_num_rows($result2);
    while($row2 = mysql_fetch_array($result2)) { echo $row2['id']} }

我想数一数我最后有多少 id 。谢谢你的帮助

4

1 回答 1

0

就给这个

$select = "SELECT X FROM Y"

$result = mysql_query($select,$link);

$total = mysql_num_rows($result);

$finalTotal=0;
while($row = mysql_fetch_array($result)) {

$Name = $row['X'];
$select2 = "SELECT id FROM `".$Name."` ";
$result2 = mysql_query($select2,$link) or die ('Erreur : '.mysql_error() );
$total2 = mysql_num_rows($result2);
 $finalTotal = $finalTotal + $total2;
while($row2 = mysql_fetch_array($result2)) { echo $row2['id'];} }

echo "total id is ".$finalTotal;

$finalTotal 将向您显示 id 的总数

于 2013-04-19T13:14:02.997 回答