SO私は次の結果を得るクエリを作成しました
+---------------+---------------+---------+---------
| 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になる収益の合計をエコーすることです。どうすればそれを行うことができますか?