运行SQl查询以返回查询的总计数。
此代码在使用PHPmyAdmin
运行SQL时有效但是在页面上它没有显示计数的回声?
不确定我是否可以在这里忽略一些东西。
非常感谢!
$sql2=mysql_query("SELECT count(*)
FROM main_table LEFT JOIN houses ON main_table.housenumber = houses.housenumber AND main_table.streetname = houses.streetname
WHERE main_table.city='1'
group by main_table.city ORDER BY average DESC, houseID DESC, reviewID DESC;");
while($row=mysql_fetch_array($sql2))
{
$count=$row['count'];
echo $count;;
}
答案 0 :(得分:1)
试试这个......
$sql2=mysql_query("SELECT
COUNT(*) AS count
FROM
main_table
LEFT JOIN houses
ON main_table.housenumber = houses.housenumber
AND main_table.streetname = houses.streetname
WHERE main_table.city = '1'
GROUP BY main_table.city
ORDER BY average DESC,
houseID DESC,
reviewID DESC") ;
while($row=mysql_fetch_array($sql2))
{
$count=$row['count'];
echo $count;
}
您的查询中有错误,您不是在选择别名时添加计数,而在使用别名时将其添加到下面。试试这个。
答案 1 :(得分:0)
为您的专栏命名:
...mysql_query("SELECT count(*) as count....
答案 2 :(得分:0)
添加SELECT count(*) as 'count' from
...
答案 3 :(得分:0)
尝试使用以下命令启动查询:
SELECT count(*) as count ...