$st = $this->db->prepare("SELECT * FROM users WHERE id=? ORDER BY id ASC");
$st->execute(array($id));
if($st->rowCount() >= 1){
foreach ($st as $row) {
echo $row["exp"]."+";
}
}
所以我尝试的是回显$row["exp"]."+";
只是添加一个循环,但它只是打印出来。我该如何解决?
答案 0 :(得分:0)
试试这个
$st = $this->db->prepare("SELECT * FROM users WHERE id=? ORDER BY id ASC");
$st->execute(array($id));
$sum=0;
if($st->rowCount() >= 1){
foreach ($st as $row) {
$sum += $row["exp"];
}
echo $sum
}
你也可以通过单个查询SELECT SUM(exp)得到exp的总和作为exp FROM users WHERE id =? ORDER BY id ASC
答案 1 :(得分:0)
在这里,这应该为您提供所需的所有答案:http://www.homeandlearn.co.uk/php/php.html
请特别注意第6节Addition in PHP