SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2010
    Posts
    453
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Trouble with a google script

    I'm trying to use this script from: https://developers.g...cles/phpsqlajax

    Google calls this script: phpsqlajax_genxml.php

    I've checked the php_domxml extension and restarted my wampserver. I'm running php 5.2.9-2.

    I've defined $username, $password, and $database per instructions in a script called phpsqlajax_dbinfo.php.

    It's causing errors. Do you know what's causing these problems?

    Warning: domnode::append_child() expects parameter 1 to be object, null given in E:\wamp\www\phpsqlajax_genxml.php on line 7

    Notice: Use of undefined constant localhost - assumed 'localhost' in E:\wamp\www\phpsqlajax_genxml.php on line 10

    Notice: Undefined variable: username in E:\wamp\www\phpsqlajax_genxml.php on line 10

    Notice: Undefined variable: password in E:\wamp\www\phpsqlajax_genxml.php on line 10

    Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'ODBC'@'localhost' (using password: NO) in E:\wamp\www\phpsqlajax_genxml.php on line 10 Not connected : Access denied for user 'ODBC'@'localhost' (using password: NO)
    PHP Code:
    <?php
    require("phpsqlajax_dbinfo.php");
             
    // Start XML file, create parent node
    $doc domxml_new_doc("1.0");
    $node $doc->create_element("markers");
    $parnode $doc->append_child($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());
    }

    // Select all the rows in the markers table
    $query "SELECT * FROM markers WHERE 1";
    $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->create_element("marker");
      
    $newnode $parnode->append_child($node);

      
    $newnode->set_attribute("name"$row['name']);
      
    $newnode->set_attribute("address"$row['address']);
      
    $newnode->set_attribute("lat"$row['lat']);
      
    $newnode->set_attribute("lng"$row['lng']);
      
    $newnode->set_attribute("type"$row['type']);
    }

    $xmlfile $doc->dump_mem();
    echo 
    $xmlfile;

    ?>

  2. #2
    SitePoint Evangelist
    Join Date
    Jun 2010
    Posts
    453
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Apparently the original script is for PHP4 according to: http://stackoverflow...ith-google-maps

    Here's the php5 version, but it still produces this error :

    any ideas?

    Fatal error: Call to undefined function DOMDocument() in E:\wamp\www\phpsqlajax_genxml.php on line 6

    I changed line 6 from $doc = new DOMDocument("1.0"); to $doc = DOMDocument("1.0");

    I couldn't find new DOMDocument in the manual.

    Code:
     
    
    <?php
    require("phpsqlajax_dbinfo.php");
    
    // Start XML file, create parent node
    $doc = DOMDocument("1.0");
    $node = $doc->createElement("markers");
    $parnode = $doc->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());
    }
    
    // Select all the rows in the markers table
    $query = "SELECT * FROM markers WHERE 1";
    $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->set_attribute("name", $row['name']);
      $newnode->set_attribute("address", $row['address']);
      $newnode->set_attribute("lat", $row['lat']);
      $newnode->set_attribute("lng", $row['lng']);
      $newnode->set_attribute("type", $row['type']);
    }
    
    echo $doc->saveXML();
    
    ?>

  3. #3
    SitePoint Evangelist
    Join Date
    Jun 2010
    Posts
    453
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Line 6 should be: $doc = new DOMDocument("1.0");

    instead of: $doc = DOMDocument("1.0");

    according to: http://php.net/manual/en/domdocument.construct.php

    The error messages now are:

    Warning: domdocument::domdocument() [domdocument.domdocument]: Entity: line 1: parser error : Start tag expected, '<' not found in E:\wamp\www\phpsqlajax_genxml.php on line 6

    Warning: domdocument::domdocument() [domdocument.domdocument]: 1.0 in E:\wamp\www\phpsqlajax_genxml.php on line 6

    Warning: domdocument::domdocument() [domdocument.domdocument]: ^ in E:\wamp\www\phpsqlajax_genxml.php on line 6

    Fatal error: Call to undefined method domdocument::createElement() in E:\wamp\www\phpsqlajax_genxml.php on line 7

  4. #4
    SitePoint Evangelist
    Join Date
    Jun 2010
    Posts
    453
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I found that I can dynamically edit the google iframe with my own code and by pass all the disfunctional google code.

    You get the iframe from the link button on a google map. It will look like this:
    Code:
    <iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=7327+S+30th+St,+Lincoln,+NE&amp;aq=&amp;sll=40.810476,-96.678362&amp;sspn=0.008819,0.020041&amp;ie=UTF8&amp;hq=&amp;hnear=7327+S+30th+St,+Lincoln,+Nebraska+68516&amp;ll=40.737174,-96.675671&amp;spn=0.008828,0.020041&amp;t=m&amp;z=14&amp;iwloc=A&amp;output=embed"></iframe><br /><small><a href="http://maps.google.com/maps?f=q&amp;source=embed&amp;hl=en&amp;geocode=&amp;q=7327+S+30th+St,+Lincoln,+NE&amp;aq=&amp;sll=40.810476,-96.678362&amp;sspn=0.008819,0.020041&amp;ie=UTF8&amp;hq=&amp;hnear=7327+S+30th+St,+Lincoln,+Nebraska+68516&amp;ll=40.737174,-96.675671&amp;spn=0.008828,0.020041&amp;t=m&amp;z=14&amp;iwloc=A" style="color:#0000FF;text-align:left">View Larger Map</a></small>
    You can make it dynamic like this:
    Code:
    <?php
    $hn = "7327";
    $dir = "S";
    $sn = "30th";
    $stype = "St";
    $city = "Lincoln";
    $st = "Nebraska";
    $zip = "68516";
    $locationString = "$hn,+$dir,+$sn,+$stype,+$city,+$st,+$zip";
    
    ?>
    <iframe width="225" height="150" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?q=4<?php echo $locationString; ?>&amp;oe=utf-8&amp;client=firefox-a&amp;ie=UTF8&amp;hq=&amp;hnear=<?php echo $locationString; ?>&amp;ll=&amp;spn=0.008827,0.020041&amp;t=m&amp;z=14&amp;output=embed"></iframe><br /><small><a href="http://maps.google.com/maps?q=<?php echo $locationString; ?>&amp;oe=utf-8&amp;client=firefox-a&amp;ie=UTF8&amp;hq=&amp;hnear=<?php echo $locationString; ?>&amp;ll=&amp;spn=0.008827,0.020041&amp;t=m&amp;z=14&amp;source=embed" style="color:#0000FF;text-align:left">View Larger Map</a></small>
    Google sucked 6 hours out of my life playing with their tutorial.

    Altering their iframe took about 20 min. Obviously, I still have to connect it with a table.

    Time to hit the rack.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •