我有这个代码,它计算列中的所有行correct并igonringLIMIT 5
被忽略的代码行
$last5rate = $db->prepare("select sum(correct)
from exams where username = :username ORDER BY testID DESC LIMIT 5");
Run Code Online (Sandbox Code Playgroud)
这是整个代码
<?php
require('includes/config.php');
//if not logged in redirect to login page
if(!$user->is_logged_in()){ header('Location: login.php'); }
$username = $_SESSION['username'];
$last5rate = $db->prepare("select sum(correct) from exams where username = :username ORDER BY testID DESC LIMIT 5");
$last5rate->execute(array(':username' => $username));
for($i=0; $rows = $last5rate->fetch(); $i++){
//Edit this row
$last5 = $rows['sum(correct)'];
$last5final = $last5 / 10;
}
echo $last5final;
?>
Run Code Online (Sandbox Code Playgroud)
我尝试了以下方法 …