我的MySQL查询只显示一行(而不是所有行),但是当我对查询执行COUNT时,它会在查询中显示正确的行数。这里似乎有什么问题?
$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']}";
}
答案 0 :(得分:4)
您正在使用不带COUNT
的聚合函数(GROUP BY
)。在这种情况下,假设只返回一行。