Passing Parameters using PHP
Posted: Thu Sep 29, 2011 6:33 pm
I'm trying to pass query parameters via the URL to the PHP. Below is the link:
http://www.icliqz.com/Dev/phpsqlsearch_ ... &radius=20
I was expecting xml of the results after passing the parameters, but I'm not recieving any results. I'm not sure what I'm doing wrong.
I checked the SQL that is retrieving the results, and it's working:
SELECT user, latitude, longitude, ( 3959 * acos( cos( radians( 41.7636111 ) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians( -72.6855556 ) ) + sin( radians( 41.7636111 ) ) * sin( radians( latitude ) ) ) ) AS distance FROM tbl_UserLatLng HAVING distance <20 ORDER BY distance LIMIT 0 , 20
Below is the PHP code I'm using:
I'm not sure what I'm doing wrong.
http://www.icliqz.com/Dev/phpsqlsearch_ ... &radius=20
I was expecting xml of the results after passing the parameters, but I'm not recieving any results. I'm not sure what I'm doing wrong.
I checked the SQL that is retrieving the results, and it's working:
SELECT user, latitude, longitude, ( 3959 * acos( cos( radians( 41.7636111 ) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians( -72.6855556 ) ) + sin( radians( 41.7636111 ) ) * sin( radians( latitude ) ) ) ) AS distance FROM tbl_UserLatLng HAVING distance <20 ORDER BY distance LIMIT 0 , 20
Below is the PHP code I'm using:
Code: Select all
// Select all the rows in the markers table
$query = sprintf("SELECT user, latitude, longitude, ( 3959 * acos( cos( radians( '%s') ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians( '%s' ) ) + sin( radians( '%s' ) ) * sin( radians( latitude ) ) ) ) AS distance
FROM tbl_UserLatLng
HAVING distance <'%s'
ORDER BY distance
LIMIT 0 , 20",
mysql_real_escape_string($center_lat),
mysql_real_escape_string($center_lng),
mysql_real_escape_string($center_lat),
mysql_real_escape_string($radius));
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
header("Content-type: text/xml");
// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
// ADD TO XML DOCUMENT NODE
$node = $doc->createElement("marker");
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("user", $row['user']);
$newnode->setAttribute("latitude", $row['latitude']);
$newnode->setAttribute("longitude", $row['longitude']);
$newnode->setAttribute("distance", $row['distance']);
}
echo $doc->saveXML();