I want to echo the total amount of a specific column value from the table
For example;
I want to echo, males
in the column gender
= 3
Similarly below, Helsinki
in the column city
= 2
Result
Males: 3
Helsinki:2
This will fetch the total amount of all the table rows:
<?php
$conn = new mysqli("localhost", "root", "", "db_name");
if ($conn->connect_errno) {
echo "Error: " . $conn->connect_error;}
$sql = "SELECT * FROM tableName";
if ($stmt = $conn->prepare($sql)) {
$stmt->execute();
$stmt->store_result();
printf("Total: %d\n", $stmt->num_rows);}
?>
You need to do 2 requests or more. 1 request by col.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.