I am getting content from my sql database with the following code which works fine:
SELECT *
FROM tbl_listings
WHERE postcode = 'var1' AND catID = 'var2' AND stateID = 'var3'
ORDER BY listingName ASC
using the following variables
name: var1
default value: -1
run-time value: $_GET['postcode']
name: var2
default value: -1
run-time value: $_GET['catID']
name: var3
default value: -1
run-time value: $_GET['stateID']
I, however, want to get the category name from the category table using a join so I tried this:
SELECT *
FROM tbl_listings LEFT JOIN tbl_category ON tbl_listings.catID = tbl_category.catID
WHERE postcode = 'var1' AND catID = 'var2' AND stateID = 'var3'
ORDER BY listingName ASC
using the following variables
name: var1
default value: -1
run-time value: $_GET['postcode']
name: var2
default value: -1
run-time value: $_GET['catID']
name: var3
default value: -1
run-time value: $_GET['stateID']
This gives me an error saying: Column: 'catID' in where clause in ambiguous.
Any ideas as to how I should be writing this code in order to filter it by the set variables and still join the category table in order to get the category name? Thanks.