[英]SQL query not returning count value
SQl query running to return the total count from the query. SQl查询运行以从查询中返回总数。
this code works when running SQL with PHPmyAdmin 使用PHPmyAdmin运行SQL时,此代码有效
But on the page it is not displaying echo of the count ? 但是在页面上没有显示计数的回声吗?
Not sure if I could have overlooked something here. 不知道我是否可以忽略这里的内容。
Many Thanks! 非常感谢!
$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;;
}
Try this .... 尝试这个 ....
$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;
}
You have mistake in your query, you are not adding count in select as aliases, and below in while you are using aliases . 您的查询有误,没有在select作为别名中添加计数,而在使用Alias中的下面添加计数。 Try this.
尝试这个。
命名您的专栏:
...mysql_query("SELECT count(*) as count....
SELECT count(*) as 'count' from
...添加SELECT count(*) as 'count' from
尝试使用以下命令启动查询:
SELECT count(*) as count ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.