1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Pleeeease Heeelllp

Discussion in 'PHP' started by cgo85, Apr 4, 2008.

  1. #1
    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&amp;v=2&amp;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>
     
    cgo85, Apr 4, 2008 IP
  2. decepti0n

    decepti0n Peon

    Messages:
    519
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    0
    #2
    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
     
    decepti0n, Apr 4, 2008 IP
  3. blognol

    blognol Peon

    Messages:
    87
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Hi,

    Just change the below
    $long = $myrow["long"];
    $long = $myrow["lat"];


    to

    $long = $myrow["long"];
    $lat = $myrow["lat"];
     
    blognol, Apr 5, 2008 IP
  4. cgo85

    cgo85 Peon

    Messages:
    380
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #4
    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
     
    cgo85, Apr 5, 2008 IP
  5. DartPHP

    DartPHP Banned

    Messages:
    71
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    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.
     
    DartPHP, Apr 5, 2008 IP
  6. cgo85

    cgo85 Peon

    Messages:
    380
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #6
    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.
     
    cgo85, Apr 5, 2008 IP
  7. Dagon

    Dagon Active Member

    Messages:
    122
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    60
    #7
    Rename your db column to longitude ;)
     
    Dagon, Apr 6, 2008 IP
  8. Dagon

    Dagon Active Member

    Messages:
    122
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    60
    #8
    or change your query to:

    $query = "SELECT `long`, `lat` FROM populate WHERE city='$city' AND state='$state'";
     
    Dagon, Apr 6, 2008 IP
  9. cgo85

    cgo85 Peon

    Messages:
    380
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Great That Worked! Thanks Everyone!
     
    cgo85, Apr 7, 2008 IP
  10. matthewrobertbell

    matthewrobertbell Peon

    Messages:
    781
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #10
    It's best pratice to use mysql_real_escape_string() on all user input that interacts with a database, including get and post data.
     
    matthewrobertbell, Apr 7, 2008 IP