Jump to content

mysql_fetch_assoc() keeps returning false


warlock

Recommended Posts

I am working on this store locate script that is available from Pamela Fox at http://code.google.com/apis/maps/articles/phpsqlsearch.html#wheretogo .  However, I am having some issues when I try to run the script.  Basically, lat, lng, and radius are posted to the script which goes through a MYSQL db and returns in order the stores within the search grid.  The xml file never displays data.  For some reason, the code:

 

$row = mysql_fetch_assoc($result)

 

returns false in the while loop causing the statements within to never execute. 

 

I would appreciate any guidance to what may be the reasoning.

 

Thank you.

 

 

<?php 

require("phpsqlsearch_dbinfo.php");

 

// Get parameters from URL

$center_lat = $_GET["lat"];

$center_lng = $_GET["lng"];

$radius = $_GET["radius"];

 

// Start XML file, create parent node

$dom = new DOMDocument("1.0");

$node = $dom->createElement("markers");

$parnode = $dom->appendChild($node);

 

// Opens a connection to a mySQL server

$connection=mysql_connect ('63.165.0.24:3306', $username, $password);

if (!$connection) {

  die("Not connected : " . mysql_error());

}

 

// Set the active mySQL database

$db_selected = mysql_select_db($database, $connection);

if (!$db_selected) {

  die ("Can\'t use db : " . mysql_error());

}

 

 

 

// Search the rows in the markers table

$query = sprintf("SELECT address, name, lat, lng, ( 3959 * acos( cos( radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance FROM markers 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);

 

$result = mysql_query($query);

if (!$result) {

  die("Invalid query: " . mysql_error());

}

 

 

 

// Iterate through the rows, adding XML nodes for eac

 

while ($row = mysql_fetch_assoc($result)) {

  $node = $dom->createElement("marker");

  $newnode = $parnode->appendChild($node);

  $newnode->setAttribute("name", $row['name']);

  $newnode->setAttribute("address", $row['address']);

  $newnode->setAttribute("lat", $row['lat']);

  $newnode->setAttribute("lng", $row['lng']);

  $newnode->setAttribute("distance", $row['distance']);

 

}

 

echo $dom->saveXML();

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.