Reputation: 921
In theory, I have two columns like so:
I want the result to be dog 6, and Elephant 2. What I have made so far (and failed [the amount does not get displayed]) is this:
$query_check_credentials = "SELECT word, SUM(amount) FROM Data Group By word";
$result = mysqli_query($dbc, $query_check_credentials);
while($row = mysqli_fetch_array( $result ))
{
echo $row['amount'];
}
Upvotes: 1
Views: 693
Reputation: 780889
You should give an alias to the sum:
SELECT word, SUM(amount) AS total_amount FROM Data GROUP BY word
and then use $row['total_amount']
.
If you don't do that, you have to use $row['SUM(amount)']
Upvotes: 3