<?php

  $host
="host_db";
  
$user="nome_utente";
  
$password="password";
  
$databs="nome_database";
        
  
$connessione=mysql_connect($host,$user,$password);

    if(!
$connessione) {
        
      echo 
"ERRORE! Impossibile Collegarsi al Database.";
          
      exit(
0);
          
    }
        
  
$db=mysql_select_db($databs);
  
  
$api_key "tua_chiave";

    
$query "SELECT * FROM restaurant";
    
$result mysql_query $query$connessione );
    if ( 
mysql_error() != ) {
        
      echo 
"Errore di query: " mysql_error();
      exit(
0);    
        
    }
              
    
$totale mysql_num_rows$result );
              
    
$ntot "<input type='hidden' id='totale' value='" $totale "'>";

    
$restot "";

    
$i 0;

    while( 
$row mysql_fetch_array $result ) ) {
              
      
$restot .= "
      <input type='hidden' id='indirizzo" 
$i "' value='" $row["indirizzo"] . "'>
      <input type='hidden' id='nome" 
$i "' value='" $row["nome"] . "'>
      <input type='hidden' id='lati" 
$i "' value='" $row["latit"] . "'>
      <input type='hidden' id='longi" 
$i "' value='" $row["long"] . "'>";

      
$i++;

      }
              
    
mysql_close $connessione );

?>

<!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>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>Google Mashup by A35G</title>
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=<?php echo $api_key ?>" type="text/javascript"></script>
    <script type="text/javascript">
      //<![CDATA[

        var coords = [];
                
        // Zoom sulla mappa al caricamento della pagina
                
        var zoom = 11;
                
        // Impostare a false per nascondere le coordinate
                
        var debug = true;

          function load() {

            if (debug) document.getElementById("debug").style.display="block";
                
            if (GBrowserIsCompatible()) {
                
              var map = new GMap2(document.getElementById("map"));

              // Inserimento dei Controlli per Zoom e Tipologia di Visibilità delle mappe
              map.addControl(new GSmallMapControl());
              map.addControl(new GMapTypeControl());

              if (debug) {
              
                GEvent.addListener(map, "moveend", function() {
                
                  var center = map.getCenter();
                  document.getElementById("debug").innerHTML = center.toString();});
          
                GEvent.addListener(map, "click", function(marker, point) {
                
                  if (point)
                  
                    document.getElementById("debug").innerHTML = point.toString();
                    
                  else
                  
                    alert(document.getElementById('indirizzo'+i).value+" .Indirizzo non trovato!");});
          
              }

          function LatLngAddr(lar,log,nome,via) {
                    
            var point = new GLatLng(lar,log);
                        
              // Crea il marker
              map.setCenter(new GLatLng(lar,log),zoom);
                                
              var marker = new GMarker(point, icon);
                                
              // Contenuto del fumetto                                
              var myHtml = "<strong>" + nome + "</strong><br /><strong>Indirizzo: " + via + "</strong>";
                                
              // Crea la finestra
              GEvent.addListener(marker, "click", function() {

                marker.openInfoWindowHtml(myHtml); });
                                    
                map.addOverlay(marker);

              }
                    
          for (var i = 0; i < document.getElementById('totale').value; i++) {
                    
            coords[i] = LatLngAddr(document.getElementById('lati'+i).value, document.getElementById('longi'+i).value, document.getElementById('indirizzo'+i).value, document.getElementById('nome'+i).value);
                        
          }
                    
        }
        
      }
      //]]>
    </script>
  </head>
  <body onload="load()" onunload="GUnload()">
    
    <?php
            
      
echo $ntot $restot;
        
    
?>
        
    <div id="map" style="width: 500px; height: 300px"></div>
        
    <div id="debug" style="display:none"></div>
        
  </body>
</html>