Visualizzazione dei risultati da 1 a 5 su 5
  1. #1
    Utente di HTML.it
    Registrato dal
    May 2010
    Messaggi
    144

    problema doppia select,ajax

    Ciao a tutti!

    Allora ho un problemino... Allora nel database ho una tabella con dentro attributi come id,fila, posto ecc...

    Ora io ho una select in cui campaiono le varie file (in maniera distinct) e quando sceglo il numero che desidero mi stampa sotto una tabella con tutti i posti per quella fila che ho scelto.

    Io vorrei però che invece che stampare così una tabella, mi infili i vari posti dentro un'altra select ed in base al posto scelto mi stampi in una tabella fila e posto scelto. Come posso fare? Vi posto qui il mio codice...

    provasito3.php
    Codice PHP:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>Post</title>
    </head>
    <body>
    <div id="xmldata"></div>
    <script type="text/javascript"> 

    function readyAJAX() { 
    try { 
        return new XMLHttpRequest(); 
    } catch(e) { 
        try { 
            return new ActiveXObject('Msxml2.XMLHTTP'); 
        } catch(e) { 
            try { 
                return new ActiveXObject('Microsoft.XMLHTTP'); 
            } catch(e) { 
                return "Hai bisogno di un altro browser."; 
            } 
        } 



    function mostraInfo(data)
    {
    var requestObj = readyAJAX(); 
    var url = "mostra_utenti_prova3.php"; 
    var params = "q=" + data;

    requestObj.open("POST",url,true); 
    requestObj.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
    requestObj.send(params); 

    requestObj.onreadystatechange = function() { 
        if (requestObj.readyState == 4) {  
            if (requestObj.status == 200) { 
       var serverResponse = requestObj.responseXML;
       var header = serverResponse.getElementsByTagName("user");

       htmlString = "<table><tr><th>Fila</th><th>Posto</th></tr>";
            
       for (i=0; i<header.length; i++)
       {
          htmlString += "<tr>";
          if (window.ActiveXObject)
          {
             htmlString += "<td>" + header[i].childNodes[0].text + "</td>";
             htmlString += "<td>" + header[i].childNodes[1].text + "</td>";

       
          }
          else
          {
             htmlString += "<td>" + header[i].childNodes[0].textContent + "</td>";
             htmlString += "<td>" + header[i].childNodes[1].textContent + "</td>";
           
             
          }
          htmlString += "</tr>";
       }
       htmlString += "</table>";

       document.getElementById('info').innerHTML = htmlString;    

            } else { 
                alert(requestObj.statusText); 
            } 
        } 

    }
    </script> 


    <form>
     <form>
    Seleziona fila: 
    <select name="users" onChange="mostraInfo(this.value)"> 
    <?php 

    $db_host 
    "localhost"
    $db_user "administrator"
    $db_password "administrator"
    $db_database "ticket"

    //Seleziono quelli che sono i dipendenti 
    $connessione mysql_connect($db_host,$db_user,$db_password); 
    mysql_select_db($db_database$connessione); 

    $query "SELECT distinct fila
    FROM teatro 
    WHERE disp='true' AND tempo='true' 
    ORDER BY fila "

    $result mysql_query($query); 
    while(
    $riga mysql_fetch_array($result)){ 
    echo 
    "<option value='$riga[fila]'>$riga[fila] </option>"
     

    ?> 
    </select> 
    </form>
     
     
     

     



    <div id="info"></div>

     

    </body> 
    </html>
    mostra_utenti_prova3.php

    Codice PHP:
    <?php 
    header
    ('Content-Type: text/xml');

    $db_host "localhost"
    $db_user "administrator"
    $db_password "administrator"
    $db_database "ticket"

    $con mysql_connect($db_host,$db_user,$db_password); 
    mysql_select_db($db_database$con); 


    $q=$_POST['q']; 

    $sql="SELECT * 
    FROM teatro 
    WHERE fila = '"
    .$q."' "

    $result mysql_query($sql); 

    $xml = new DomDocument('1.0'); 
        
    $info $xml->createElement('informations'); 
        
    $info $xml->appendChild($info); 

       
    while (
    $row mysql_fetch_array($result))
        {
            
            
    $user $xml-> createElement('user');
            
    $user $info->appendChild($user);
            
            
    $fila $xml->createElement('fila');
            
    $fila $user->appendChild($fila);
            
    $value $xml->createTextNode($row['fila']);
            
    $value $fila->appendChild($value);
            
            
    $posto $xml->createElement('posto');
            
    $posto $user->appendChild($posto);
            
    $value $xml->createTextNode($row['posto']);
            
    $value $posto->appendChild($value);     
         
         
            
        }
             
    $output $xml->saveXML();

    echo 
    $output;

    ?>
    Aspettando una risposta
    Grazie mille!

  2. #2
    se vuoi il cambiamento senza dover cambiare pagina... è un problema di javascript e troverai più aiuto in quella sezione

  3. #3
    Utente di HTML.it
    Registrato dal
    May 2010
    Messaggi
    144
    Si ma io sto utilizzando php con xml e ajax... però questo è codice xml e php...

  4. #4
    Il problema è php? No.

    Il problema è che ora ti crea una tabella, però vuoi che alla scelta Javascript ti metta i dati in una select giusto? In questo caso è Javascript che devi toccare.

  5. #5
    Utente di HTML.it
    Registrato dal
    May 2010
    Messaggi
    144
    Si hai ragione... ma ci ho rinunciato
    Quindi ho cambiato problema
    Ho postato il problema qui:
    http://forum.html.it/forum/showthrea...5#post12986265

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.