我对此有疑问:

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进行计数?

最佳答案

$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";
}

09-15 16:37