PDA

View Full Version : defined field not allowed in Where clause?


boeing747fp
03-27-2010, 05:39 AM
i have the following line of php (query with variables in it) and it keeps failing saying
"unknown column 'distance' in 'where clause'"
the query works without the where clause at all, but it returns all rows and just sorts by distance... i want to be able to filter it by number of miles

$sql=mysql_query("SELECT *,3956*2*ASIN(SQRT(POWER(SIN((".$mylat." -
abs(lat))*pi()/180/2),2)+COS(".$mylat."*pi()/180)*COS(abs(lat)*pi()/180)*POWER
(SIN((".$mylon."-lon)*pi()/180/2),2))) as `distance` FROM `listings` WHERE
`distance` <= ".$_REQUEST['miles']." ORDER BY `distance` ASC");

any ideas?

abduraooft
03-27-2010, 08:30 AM
WHERE
`distance` <= ".$_REQUEST['miles']." ORDER BY `distance` ASC"
Try HAVING `distance` <= ".$_REQUEST['miles']." ORDER BY `distance` ASC"

masterofollies
03-28-2010, 12:25 AM
Also make sure your field name in the database is spelled correct. Distance and distance are two different things.

Old Pedant
03-28-2010, 04:08 AM
Also make sure your field name in the database is spelled correct. Distance and distance are two different things.

Not true.

http://dev.mysql.com/doc/refman/5.0/en/identifier-case-sensitivity.html


Column, index, and stored routine names are not case sensitive on any platform, nor are column aliases.

Other kinds of names--tables, databases, trigger, etc.--may vary from platform to platform. That section explains it well.

Mezzra
03-28-2010, 09:41 PM
Also make sure your field name in the database is spelled correct. Distance and distance are two different things.

Case sensitivity is just true for variables, no?