0

我对此有疑问:

count this id no 1 = usage/nod
count this id no 2 = (usage[id1]+usage[id2])/(nod[id1]+nod[id2])
count this id no 3 = (usage[id1]+usage[id2]+usage[id3])/(nod[id1]+nod[id2]+nod[id3])

等等...

“用法/点头”是数据库中的一个字段。

我怎么能用 PHP 和 MySQL 来计算呢?

4

1 回答 1

1
$total_usage = 0;
$total_nod = 0;

while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
    $total_usage += $row['usage'];
    $total_nod += $row['nod'];
    $div = $total_usage/$total_nod;
    echo "count this id no $row[id] = $div\n";
}
于 2013-05-06T15:07:01.653 回答