所以我做了一个查询,得到以下结果
+---------------+---------------+---------+---------
| payID | payRate | hours | Earnings
+---------------+---------------+---------+--------
| entertainment| 12 | 18 | 216
| retail | 10 | 28 | 280
+---------------+---------------+---------+----------
查询和其他一些代码部分如下:
$query = "SELECT jobId, payRate, SUM(hours) AS 'All_Hours' ,payRate * SUM(hours) AS 'total'
FROM users INNER JOIN deposit ON userId = empId
WHERE users.email = '" . $_SESSION['email'] ."'
GROUP BY jobId,payRate";
$result = mysqli_query($db, $query); //we make the query
if (!$result) { //if the query failed
echo("<p id = 'greatideadescription'>
Error, the query could not be executed: " .
mysqli_error($db) . "</p>");
mysqli_close($db);}
if (mysqli_num_rows($result) == 0) { //if no rows returned
echo("<tr><td />
<td>No Results</td>
<td /></tr>");
mysqli_close($db); //close the database
exit("</table></div></form></div></div>
<script>DisplayFooter();</script></body></html>");
}
$numRows = mysqli_num_rows($result); //gets number of rows
$numFields = mysqli_num_fields($result); //gets number of fields
//prints the data in the table
PrintTable($result, $numRows, $numFields);
函数PrintTable如下
function PrintTable($result, $numRows, $numFields) {
$row = mysqli_fetch_row($result); //fetches the first row
for ($i = 0; $i < $numRows; $i++) {
echo("<tr>"); //opens a new row
for ($j = 0; $j < $numFields; $j++) { //second loop goes through columns
echo("<td>" . $row[$j] . "</td>");
} //end inner for loop
$row = mysqli_fetch_row($result); //fetches subsequent rows
echo("</tr>"); //closes the row
} //end outer for loop
}
我想要的是呼应收入的总和,在这种情况下它将是 496 我该怎么做?