0

My MySQL query is displaying just one row (instead of all of the rows), but when I do a COUNT on the query, it shows the correct number of rows in the query. What seems to be the problem here?

$sql5 = "SELECT m.*, i.*, COUNT(*) AS num, m.id AS m_id FROM members m JOIN roommate_seek i ON m.id = i.member_id
              WHERE _school = :school AND i.category = :category";

foreach ($db->query($sql5, array('school' => $_GET['school'], 'category' => $category)) AS $result3)
{
    echo "{$result3['m_id']}";
}

1 Answer 1

4

You are using an aggregate function (COUNT) without GROUP BY. In that case it is suppose to return exactly one row.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.