jcbrmn06 Posted July 27, 2010 Share Posted July 27, 2010 MySQL server version is 5.1.44 and i downloaded XAMPP package for Mac OS X. I am trying to create a store locator for a client of mine. I found this http://code.google.com/apis/maps/articles/phpsqlsearch.html on google. I went into this knowing nothing about MySQL and PHP, over the past few days i have been working on this and trying to get it to work. I have managed to get the map to come up and even connect to the database that i want to. Problem is when i go to search i keep coming up with "No results found". I guess my question is, what do you exactly have to do with the database? right now i exported it as an SQL and have it in the same folder as my .php file. Any ideas on how i can get this to work?? Any help would be greatly appreciated considering i know very very little about MySQL and PHP. Thanks. Link to comment https://forums.phpfreaks.com/topic/209036-store-locator-with-php-and-mysql/ Share on other sites More sharing options...
systemick Posted July 27, 2010 Share Posted July 27, 2010 Could you give a little more detail about what you have done and the problems you are having. How are you querying the database. Do you have any PHP code that you could put on here. Link to comment https://forums.phpfreaks.com/topic/209036-store-locator-with-php-and-mysql/#findComment-1091814 Share on other sites More sharing options...
jcbrmn06 Posted July 27, 2010 Author Share Posted July 27, 2010 well i got this far: It seems like it is not picking up the database that i want it to. So i have a feeling that i may have put it in the wrong place or something. Also looking over that google article it wants to "Outputting XML with PHP" which i am guessing how i am querying it. This code below is what the article tells me to output it to XML. in the article below this code it wants me to test it. "Call this PHP script from the browser to make sure it's producing valid XML." I do not really know what the article means by calling this PHP script from the browser... <?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 (localhost, $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()); } header("Content-type: text/xml"); // Iterate through the rows, adding XML nodes for each 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(); ?> Hope this helps a little bit more. Link to comment https://forums.phpfreaks.com/topic/209036-store-locator-with-php-and-mysql/#findComment-1091820 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.