Okay, I'm trying to get longitude/Lat from my db and place it into a gmaps app. Below is the code I have... I just can't figure out how to make this work. Your help is much appreciated. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <?php //get variables from url $city = $_GET['city']; $state = $_GET['state']; $county = $_GET['county']; include 'config.php'; include 'opendb.php'; $query = "SELECT long, lat FROM populate WHERE city='$city' AND state='$state'"; $result = mysql_query($query); $myrow = mysql_fetch_array($result); $long = $myrow["long"]; $long = $myrow["lat"]; include 'closedb.php'; ?> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <title>Google Maps JavaScript API Example</title> <script src="http://maps.google.com/maps?file=api&v=2&key=<?= $google_api_key; ?>" type="text/javascript"></script> <script type="text/javascript"> //<![CDATA[ function load() { if (GBrowserIsCompatible()) { var map = new GMap2(document.getElementById("map")); map.setCenter(new GLatLng(<?= $lat; ?>, <?= $long; ?>), 13); } } //]]> </script> </head> <body onload="load()" onunload="GUnload()"> <div id="map" style="width: 500px; height: 300px"></div> </body> </html>
You have $long twice for one - so it'd make latitude and longitude the same. Does it actually return anything? The code otherwise seems fine
Hi, Just change the below $long = $myrow["long"]; $long = $myrow["lat"]; to $long = $myrow["long"]; $lat = $myrow["lat"];
that didn't work. It gives me an error message that says: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/coyoloko/public_html/my_test_stuff/g_maps.php on line 17
What I would do is change $result = mysql_query($query); to $result = mysql_query($query) or die(mysql_error()); And see if it gives you an error.
still receiving an error. Basically i just want to figure out how to change 'long' & 'lat' to a variable that i can use throughout a page.
or change your query to: $query = "SELECT `long`, `lat` FROM populate WHERE city='$city' AND state='$state'";
It's best pratice to use mysql_real_escape_string() on all user input that interacts with a database, including get and post data.