Visualizzazione dei risultati da 1 a 3 su 3

Discussione: Problema di sintassi?

  1. #1
    Utente di HTML.it
    Registrato dal
    Apr 2002
    Messaggi
    180

    Problema di sintassi?

    Ciao a tutti,
    ho un problema nel "combinare" i files tra php e html per ottenere quello che mi serve.....
    vi faccio l'esempio:
    ho un file menu.html che contiene un menu a tendina nel quale l'utente sceglie un parametro e cliccando il tasto "visualizza" richiama un file creaxml.php passando il parametro scelto alla query.
    Infatti quando clicco, si visualizza il risultato della query (in particolare viene generato il file xml relativo alla selezione effettuata).

    Il problema è che ho un altro file mappa.html che produce dei marker sulla mappa di google a partire dal file xml generato prima: il problema è che non so come integrarlo in modo che questo file html possa essere lanciato direttamente dal file menu.html. Vorrei cioè che dalla maschera inziale menu.html si passasse alla mappa con visualizzati i marker prodotti dal file xml.

    Spero di essere stato chiaro.........

    vi faccio l'esempio dei files a blocchi:
    menu.html
    <html>
    <body>
    menu tendina <form name="elab" method="post" action="./creaxml.php">
    e passa parametro "selezione"
    </body>
    </html>
    ---------------------
    creaxml.php
    <?php
    $query = "SELECT * FROM markers WHERE id='$selezione'";
    while ($row = @mysql_fetch_assoc($result)){
    crea file xml}
    echo $dom->saveXML();
    ?>
    ------------------------
    mappa. html
    <head>
    <script type="text/javascript">
    GDownloadUrl("creaxml.php", function(data) {
    crea markers dal file creaxml.php
    </script>
    </head>
    <body onload="load()" onunload="GUnload()">
    <div id="map" style="width: 800px; height: 600px"></div>
    </body>
    </html>

    Sono bloccatissimo da due giorni e non ci esco, help!
    Grazie in anticipo dell'aiuto :master:

  2. #2
    Utente di HTML.it
    Registrato dal
    Apr 2002
    Messaggi
    180
    ...allora...prova e riprova sarei riuscito ad integrare qualcosa....
    select_sel.php, che vi posto, integra sia la funzione della mappa che la ricerca con parametro passato dalla pagina del menu.

    Il problema però è che vorrei inserire ler var pin1, var pin2 (ora statici e predefiniti) nel ciclo while di restituzione dei risultati della query, in modo che venissero creati i punti della selezione del menu.
    Mi aiutate?
    thanx


    <html>
    <head>
    <title>Recupero dati da una tabella di database</title>
    <script src="http://maps.google.com/maps?file=api&v=2&
    key=ABQIAAAArSysGIurcK7dOMZla-7TExQSXE4ITa1YzwIbIoQt-CisjCLm8xS2jytkVj9gPuB1NWF-zZMCsCPqMA"

    type="text/javascript"></script>

    <script type="text/javascript">

    function initialize() {
    if (GBrowserIsCompatible()) {
    //Visualizza mappa solo modalita' stradale
    var map = new GMap2(document.getElementById("map_canvas"));

    // ITIS G. Capellini
    var center = new GLatLng(44.0750963, 10.700323);

    // Elementari Via Pascoli
    var pin1 = new GLatLng(44.113902, 9.834570);

    // Medie via Leopardi
    var pin2 = new GLatLng(44.113715, 9.833441);

    map.setCenter(center, 8);


    // L'opzione title di Gmarker fa apparire una stringa al passaggio sul marker
    var marker = new GMarker(center, {title: "Qui ho frequentato le superiori"});
    map.addOverlay(marker);
    var marker = new GMarker(pin1, {title: "Qui ho frequentato le elementari"});
    map.addOverlay(marker);
    var marker = new GMarker(pin2, {title: "Qui ho frequentato le medie"});
    map.addOverlay(marker);

    //Aggiunge i controlli formato grande
    map.addControl(new GLargeMapControl());

    //Aggiunge la scala
    map.addControl(new GScaleControl());
    }
    }
    </script>
    </head>
    <body>

    <?php
    // Si connette al database
    $connection= mysql_connect ('localhost', 'root', '') or die('Non connesso : ' . mysql_error());
    $db_selected = mysql_select_db('mappa', $connection) or die ('database non selezionato : ' . mysql_error());

    $seltipo = $_POST['seltipo'];
    $query = "SELECT * FROM markers WHERE id='$seltipo'";


    // invio la query
    $result = mysql_query($query);

    // controllo l'esito
    if (!$result) {
    die("Errore nella query $query: " . mysql_error());
    }

    // echo "

    $query </p>";
    echo '
    <table border="1" bgcolor="#FFFFFF">
    <tr bgcolor="#CCCCCC">
    <th>id</th>
    <th>denom</th>
    <th>indir</th>
    <th>lat</th>
    <th>long</th>
    <th>tipomarker</th>
    </tr>';

    while ($row = mysql_fetch_assoc($result)) {
    $codgest = htmlentities($row['id']);
    $codcom = htmlentities($row['denom']);
    $provpost = htmlentities($row['indirizzo']);
    $nompost = htmlentities($row['lat']);
    $anno = htmlentities($row['long']);
    $aggiornamento = htmlentities($row['tipomarker']);

    echo "<tr>
    <td>$codgest</td>
    <td>$codcom</td>
    <td>$provpost</td>
    <td>$nompost</td>
    <td>$anno</td>
    <td>$aggiornamento</td>
    </tr>";
    }
    echo '</table>';

    // libero la memoria di PHP occupata dai record estratti con la SELECT
    mysql_free_result($result);

    // chiudo la connessione a MySQL
    mysql_close();
    ?>
    <body onload="initialize()" onunload="GUnload()">
    <div id="map_canvas" style="width: 550px; height: 450px"></div>

    </body>
    </html>

  3. #3
    Utente di HTML.it
    Registrato dal
    Apr 2002
    Messaggi
    180
    ...sto scoppiando.........
    no, come prima non funziona.......

    vediamo così:
    il file menu.html richiama il file creaxml.php e gli passa il parametro $seltipo.

    Ecco il file creaxml.php (che dovrebbe creare anche la mappa a partire dal xml generato) e che NON FUNZIONA :

    <!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>Visualizzazione markers su Google Map tramite MySQL e PHP</title>

    <script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAArSysGIurcK7dOMZla-7TExQSXE4ITa1YzwIbIoQt-CisjCLm8xS2jytkVj9gPuB1NWF-zZMCsCPqMA"
    type="text/javascript"></script>
    <script type="text/javascript">


    function load() {
    if (GBrowserIsCompatible()) {
    var map = new GMap2(document.getElementById("map"));
    map.addControl(new GLargeMapControl());
    map.addControl(new GMapTypeControl());
    map.setCenter(new GLatLng(44.0750963, 10.700323), 8);

    GDownloadUrl("creaxml.php", function(data) {
    var xml = GXml.parse(data);
    var markers = xml.documentElement.getElementsByTagName("marker") ;
    for (var i = 0; i < markers.length; i++) {
    var denom = markers[i].getAttribute("denom");
    var indirizzo = markers[i].getAttribute("indirizzo");
    var tipomarker = markers[i].getAttribute("tipomarker");
    var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
    parseFloat(markers[i].getAttribute("long")));
    var marker = createMarker(point, denom, indirizzo, tipomarker);
    map.addOverlay(marker);
    }
    });
    }
    }


    function createMarker(point, denom) {
    var marker = new GMarker(point);

    GEvent.addListener(marker, 'mouseover', function() {
    marker.openInfoWindowHtml(denom);
    });
    return marker;
    }

    </script>
    </head>

    <?php

    $dom = new DOMDocument("1.0");
    $node = $dom->createElement("markers");
    $parnode = $dom->appendChild($node);

    // Si connette al database
    $connection= mysql_connect ('localhost', 'root', '') or die('Non connesso : ' . mysql_error());
    $db_selected = mysql_select_db('mappa', $connection) or die ('database non selezionato : ' . mysql_error());

    // Seleziona tutte le righe della tabella con i markers
    $seltipo = $_POST['seltipo'];
    $query = "SELECT * FROM markers WHERE id='$seltipo'";
    $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 = $dom->createElement("marker");
    $newnode = $parnode->appendChild($node);

    $newnode->setAttribute("name",$row['denom']);
    $newnode->setAttribute("address", $row['indirizzo']);
    $newnode->setAttribute("lat", $row['lat']);
    $newnode->setAttribute("long", $row['long']);
    $newnode->setAttribute("type", $row['tipomarker']);

    }

    echo $dom->saveXML();

    ?>

    <body onload="load()" onunload="GUnload()">
    <div id="map" style="width: 800px; height: 600px"></div>

    </body>
    </html>

    non funziona
    è un problema di ordine delle operazioni da eseguire?
    non lo so?!?!?

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.