使用sql算术查询向表显示结果

时间:2018-02-07 16:24:10

标签: php sql arithmetic-expressions

我想使用此代码

将结果显示到表中
$q = $_GET['q'];
mysqli_select_db($con,"ofes");
$sql="SELECT * FROM tbl_summative_results WHERE subject_description = '".$q."'";
$result = mysqli_query($con,$sql);

$sql1="SELECT (round(AVG(pr1+pr2+pr3+pr4+pr5+pr6+pr7+pr8+pr9)/9,2)) FROM tbl_summative_results WHERE subject_description = '".$q."'";
$results = mysqli_query($con,$sql1);
while($row = mysqli_fetch_array($results)) {
    echo "<tr>";
    echo "<td style='background-color:#e9efc4;color:black;font-weight:bold'>" . $row['(round(AVG(pr1+pr2+pr3+pr4+pr5+pr6+pr7+pr8+pr9)/9,2))'] . "</td>";
    echo "</tr>";
     mysqli_close($con);
}

当我运行代码时,我总是有错误。

1 个答案:

答案 0 :(得分:0)

我现在知道了。我使用了这个查询&#34; SELECT round(AVG(pr1 + pr2 + pr3 + pr4 + pr5 + pr6 + pr7 + pr8 + pr9)/ 9,2)FROM tbl_summative_results WHERE subject_description =&#39;&#34;。 $ q&#34;&#39;&#34 ;;&#34;