Reputation: 33
Here I am trying to get total of 5 specific rows out of 15 rows from specific column of table in mysql.
$sql = "SELECT SUM(column) FROM Table WHERE business_name= 'my business'";
$result = $conn-> query($sql);
$row = $result -> fetch_assoc();
print_r ($row);
Array ( [SUM(rating)] => )
Upvotes: 0
Views: 125
Reputation: 184
Try Count(*)
$sql = "SELECT COUNT(*) AS 'column' FROM Table WHERE business_name= 'my business'";
Upvotes: 1
Reputation: 121
You have to use an alias. $sql = "SELECT SUM(column) as ss FROM Table WHERE business_name= 'my business'";
and then fetch the data using $row['ss']
$sql = "SELECT SUM(column) as ss FROM Table WHERE business_name= 'my business'";
$result = $conn-> query($sql);
$row = $result -> fetch_assoc();
echo $row['ss'];
I hope it helps!
Upvotes: 0