0

运行 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;;
}
4

4 回答 4

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;
    }

您的查询有误,您没有在 select 中添加 count 作为别名,在使用 aliases 时也没有添加。尝试这个。

于 2013-10-13T08:05:33.073 回答
0

命名你的专栏:

...mysql_query("SELECT count(*) as count....
于 2013-10-13T07:38:05.433 回答
0

SELECT count(*) as 'count' from...

于 2013-10-13T07:38:33.693 回答
0

尝试使用以下命令开始您的查询:

SELECT count(*) as count ...
于 2013-10-13T07:38:57.770 回答