I have a problem that has been driving me batty. I have code that passes coordinates to a query function. The query works fine for latitude see below, but not longitude. I had a complex WHERE clause for both but moved to separate WHERE clauses for the two to troubleshoot. The code below shows the latitude WHERE commented out. If I reverse the commenting out, latitude works as expected. All values in the referenced database are Doubles and negative for longitude versus all positive for latitude. I have hunted for improper syntax and cannot find it. I have even rounded variables to pass, double checked column names, reversed operators, and plenty else. The two WHEREs are identical, respectively; and the longitude variables are passing cleanly based on the feedback of the error given. So, where's Waldo? Thank You!
The ERROR:
Database query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'long>=-93.497315 AND long<=-91.365967' at line 1
Calling Function:
$box=$_GET["rect"];
$box=ltrim($box,"((");
$box=rtrim($box,"))");
$boxArray = explode("), (",$box);
$sw = explode(", ",$boxArray[0]);
$ne = explode(", ",$boxArray[1]);
$swLat = round($sw[0], 6);
$swLong = round($sw[1], 6);
$neLat = round($ne[0], 6);
$neLong = round($ne[1], 6);
$job_set = get_job_by_Rectangle($swLat, $swLong, $neLat, $neLong);
while ($job = mysql_fetch_array($job_set)) {
echo $job["projectFK"] . ", ";}
Problem Function:
function get_job_by_Rectangle($swLat, $swLong, $neLat, $neLong) {
global $connection;
$query = "SELECT * ";
$query .= "FROM projcoords ";
//$query .= "WHERE lat>= " . $swLat . " AND lat<= " . $neLat . " " ;
$query .= " WHERE long>=" . $swLong . " AND long<=" . $neLong . " " ;
//$query .= " ORDER BY projectFK";
$result_set = mysql_query($query, $connection);
confirm_query($result_set);
return $result_set;
}