Im trying to get this query to work but i get this error:
Unknown column ‘zips.city’ in ‘having clause’
`$query = "SELECT
zips.*
FROM
zips
HAVING
zips.city LIKE '%$city%'
AND
zips.stateabbr LIKE '%$state%'
LIMIT 1";
$result = mysql_query($query) or die (mysql_error());`
my zips table has a city column, so im not sure what the problem is, i know im accessing the database because i can run this query with no errors:
$zip1query = "SELECT
zips.*
FROM
zips
WHERE
zips.zip = '$zip'
";
any advice would be much appreciated! thanks!
The
havingclause doesn’t mean the same thing as thewhereclause : when running a simple query, you should usewhere— which is what you did in your second query, that works.havingis used when the condition has to be applied on the result of agroup byclause.Which means that, here, your query should be build this way :
With that, if you still have an error about a non-existing or not-found column (at least for
cityand/orstateabbr), it’ll be because that column doesn’t exist in your table.In this case, there is not much we can do : you’ll have to check the structure of your table, to determine which columns it contains.
You can check that structure using a web-based tool like phpMyAdmin, or using an SQL instruction such as :
For reference, quoting MySQL’s manual page for
select: