Here is my query:
SELECT f.id AS id,
c.city AS city,
ca.category AS cat
FROM following AS f
JOIN cities AS c ON f.city=c.id
JOIN categories AS ca ON f.category=ca.id
WHERE f.member = $this->id
The problem is sometimes city
or cat
can equal 0. If they equal zero, I can't have them join the cities or categories table, as there isn't a value in the table for 0, nor do I want one.
So essentially I want the above query but I want: if city!=0
join the cities table, and if cat!=0
join the categories table.
I don't mind whether I change the PHP or the SQL, but I just can't work out how this can be achieved.