PHP and MySQL search with extra counts along the way

Posted by Barry Connolly on Stack Overflow See other posts from Stack Overflow or by Barry Connolly
Published on 2014-08-24T22:10:21Z Indexed on 2014/08/24 22:20 UTC
Read the original article Hit count: 179

Filed under:
|

I am building a PHP and MySQL search as so

SELECT * FROM Properties WHERE Locaion = 'Liverpool'

I want to count how many of each property type there are and display them at the side of the page to use as filters (like Rightmove.co.uk).

This is what I am have come up with but can't get it to work

SELECT *, 
count(PropertyType = 'house') AS HouesTotal, 
count(PropertyType = 'Apartment') AS ApartmentTotal
FROM Properties WHERE Location = 'Liverpool'

Can anyone help?

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql