Using PHP mysql_num_rows() returns "1" when running the query below on the table below when there are no matching rows present.
Upon testing I found out that the problem happens when I use the SUM() function in the query. If I take SUM() out of the query mysql_num_rows() returns "0" like it should.
Is there something else I should use instead of mysql_num_rows() to find out if there is a matching row in the table?
Table:
name | students_money | grade
George | 5 | A
Bill | 10 | A
Dan | 7 | A
Code:
$sql = "SELECT SUM(students_money) AS sum_money FROM students_table WHERE name = 'Tom' AND name = 'Jack'";
$result = @mysql_query($sql, $con) or die(mysql_error());
$num_rows = mysql_num_rows($result);
if ($num_rows < 1) {
echo "not everyone has paid";
exit;
}
while($row = mysql_fetch_array($result)) {
$sum_money = $row[sum_money];
$total = $total + $sum_money;
}