Reputation: 189
SQl query running to return the total count from the query.
this code works when running SQL with PHPmyAdmin
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;;
}
Upvotes: 0
Views: 79
Reputation: 1675
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 . Try this.
Upvotes: 1