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

    Problema link xml con setAttribute in script php

    Ciao a tutti!

    Allora avrei un piccolo problema...
    Ho realizzato queste due pagine che vi posterò sotto che in pratica producono una select e in base all'elemnto scelto dalla select interrogono il database e stampano determinate cose...
    Il problema è che io vorrei aggiungere al carrello l'elemento della tabella dinamica scelto dall'utente.

    Aggiungi al carrello l'ho messo, ho pure cambiato e non metto create textnode ma setAttribute, ma non me lo fa vedere come collegamento...
    dove è sbagliato???

    Grazie mille!

    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>"; 
             htmlString += "<td>" + header[i].childNodes[2].text + "</td>";

       
          }
          else
          {
             htmlString += "<td>" + header[i].childNodes[0].textContent + "</td>";
             htmlString += "<td>" + header[i].childNodes[1].textContent + "</td>";
             htmlString += "<td>" + header[i].childNodes[2].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);    
            
            
    $a $xml->createElement('a','Aggiungi al carrello');
            
    $a $user->appendChild($a);
            
    $value $a->setAttribute('href''ecomm_view_product.php'); 
            
    $value $a->appendChild($value);
                
           
        }
             
    $output $xml->saveXML();

    echo 
    $output;

    ?>

  2. #2
    Utente di HTML.it
    Registrato dal
    May 2010
    Messaggi
    144
    Adesso ho cambiato una cosa, mi compare il bottone invia, ma io vorrei inviare l'id...

    Codice PHP:
          if (window.ActiveXObject)
          {
             
    htmlString += "<td>" header[i].childNodes[0].text "</td>";
             
    htmlString += "<td>" header[i].childNodes[1].text "</td>"
             
    htmlString += "<td>" header[i].childNodes[2].link "</td>";
        
       
          }
          else
          {
             
    htmlString += "<td>" header[i].childNodes[0].textContent "</td>";
             
    htmlString += "<td>" header[i].childNodes[1].textContent "</td>";
             var 
    idheader[i].childNodes[2].textContent
             htmlString 
    += "<td><form action='../SITOTSWUBUNTU/ecomm_view_product.php?id=id' ><input type='submit' value='Aggiungi al carrello'>"  "</form></td>";
           
             
          } 
    e nell'altro file al posto di aggiungi al carrello ho messo:

    Codice PHP:
    $id $xml->createElement('id');
            
    $id $user->appendChild($id);
            
    $value $xml->createTextNode($row['id']);
            
    $value $id->appendChild($value); 
    Mi stampa aggiungi al carrello,mi manda al link desiderato, ma non mi manda l'id!
    dove è l'errore?
    Cmq anche se per caso nel link metto: "miofile.php?id=1"
    non me lo vede cmq... mi porta a miofile.php e basta...

    una soluzione?

  3. #3
    Utente di HTML.it
    Registrato dal
    May 2010
    Messaggi
    144
    Nessuno sa darmi una mano? Pleeease

  4. #4
    Utente di HTML.it
    Registrato dal
    May 2009
    Messaggi
    225
    il codice
    Codice PHP:
    <select name="users" onChange="mostraInfo(this.value)"
    dovresti correggerlo in
    Codice PHP:
    <select name="users" onChange="mostraInfo(this.options[this.selectedItem].value)"

  5. #5
    Utente di HTML.it
    Registrato dal
    May 2010
    Messaggi
    144
    Ho provato a sostituire la riga come dici tu, ma non mi fa più comparire nulla, solo la select, ma cambiando elementi all'interno non mi fa comparire nessuna tabella...
    cmq il file adesso è questo:

    Codice PHP:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title>Posti</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>"; 
             htmlString += "<td>" + header[i].childNodes[2].text + "</td>";
        
       
          }
          else
          {
             htmlString += "<td>" + header[i].childNodes[0].textContent + "</td>";
             htmlString += "<td>" + header[i].childNodes[1].textContent + "</td>";
             
             htmlString += "<td><form action='ecomm_view_product.php'><input type='submit' value='Aggiungi al carrello'>"  +       header[i].childNodes[2].textContent + "</form></td>";
                   
             
          }
          htmlString += "</tr>";
       }
       htmlString += "</table>";
       

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

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

    }
    </script> 


     <form >
    Seleziona fila: 
    <select name="users" onChange="mostraInfo(this.options[this.selectedItem].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>

  6. #6
    Utente di HTML.it
    Registrato dal
    May 2009
    Messaggi
    225
    scusami è selectedIndex non selectedItem

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.