0
foreach ($_POST['ECL'] as $lt) {

    //SQL select statements are run.  Each $lt is a where condition where results are obtained from the DB.
}

我想计算每个结果并总结一下。总数将是获得的记录。我可以获得每个人 $lt 的记录数,但我无法对它们求和。所有帮助将不胜感激。

[更新] $lt 的数量不固定。$lt 可以是 1,2,3,4... $i++ 等计数器不起作用

4

3 回答 3

3

在循环之前设置一个计数器,在循环期间将其递增,最后检索总和。简单的...

于 2012-04-20T14:41:36.170 回答
1

尝试使用mysql_num_rowsmssql_num_rows - 它们返回结果中的行数

$count = 0;  // setup count variable
foreach ($_POST['ECL'] as $lt) {

    //SQL select statements are run.  Each $lt is a where condition where results are obtained from the DB.
    $count += mysql_num_rows($result);  // add results count to our counter
}
echo $count; // this will be the total number of rows the queries returned
于 2012-04-20T14:44:58.483 回答
0

您的问题是您将每个 $lt 的结果行添加到一个数组中(虽然我在发布的代码中没有看到)。

如果是这种情况,并且您每行插入一个数组记录,则数组的长度应该作为您的计数。

于 2012-04-20T14:43:55.817 回答