Visualizzazione dei risultati da 1 a 10 su 15

Visualizzazione discussione

willy-70 AIUTO per select correlate... 15-09-2017, 10:22
badaze Hai bisogno di ajax. Guarda... 16-09-2017, 12:05
badaze Nel file test9369b.php ... 16-09-2017, 18:27
willy-70 Ciao !!! ho letto solo ora... 16-09-2017, 18:44
badaze Beh. La strada che prendi non... 16-09-2017, 19:34
willy-70 Grazie mille per il... 16-09-2017, 19:51
badaze Non sono sicuro di avere... 16-09-2017, 22:09
badaze Immagine 28797 16-09-2017, 22:13
willy-70 28809troppo gentile non ho... 18-09-2017, 16:57
badaze E' un errore che scatta se la... 18-09-2017, 17:47
willy-70 Ciao ! purtroppo si ti... 19-09-2017, 16:45
badaze Prova i sorgenti fuori dal... 19-09-2017, 18:20
willy-70 Ciao, ho provato mettendo... 20-09-2017, 07:09
M4V1 Wordpress ha un modo interno... 20-09-2017, 10:45
willy-70 Carissimi, ho letto i... 20-09-2017, 19:23
  1. #7
    Utente di HTML.it L'avatar di badaze
    Registrato dal
    Jun 2002
    residenza
    Lyon
    Messaggi
    5,372
    Non sono sicuro di avere capito bene. Il codice che posto visualizza un testo dopo del change sulla seconda select.

    Codice PHP:
    <!DOCTYPE html>
    <?php
    $bdd 
    = new PDO('mysql:host=127.0.0.1; dbname=tests','root','', array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,PDO::MYSQL_ATTR_LOCAL_INFILE => true));

    //------ DEBUT
    $query  "SELECT distinct(anno) FROM eventi order by anno";

    $sth    $bdd->prepare($query);
    $sth->execute();
    ?>
    <html>
    <head>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 
    <style type="text/css">
    </style>

    <script>
    function testoEvento(valore)
    {
        document.getElementById("testo_evento").innerHTML = '';
        
        $.ajax
        ({            
                type: "POST",            
                url: "test9369c.php",            
                data: {id: valore},            
                dataType: "html",            
                success: function(dati_testo){    
                    $("#testo_evento").html(dati_testo);
                    return;    
                },
                error:function(msg){
                    alert('Errore : '+msg);
                }
        }); 
        return;    
        
    }

    function riempiSecondaSelect(valore)
    {
        document.getElementById("testo_evento").innerHTML = '';
        if (valore != 0)
        {
            $.ajax
            ({            
                    type: "POST",            
                    url: "test9369b.php",            
                    data: {anno: valore},            
                    dataType: "html",            
                    success: function(dati_seconda_select){    
                        $("#div_eventi").html(dati_seconda_select);
                        testoEvento(document.getElementById("eventi").value);
                        return;    
                    },
                    error:function(msg){
                        alert('Errore : '+msg);
                    }
            }); 
        }    

        // in caso di errore non metto niente !!!
        document.getElementById("div_eventi").innerHTML = '';
        return;    
        
    }
    </script>
    </head>
    <body>

    Anno : 
    <select id="anno" onclick="riempiSecondaSelect(this.value)">
        <option value="0">Seleziona</option><?php
        
    while (list($anno) = $sth->fetch(PDO::FETCH_NUM)) 
        {
    ?>
            <option value="<?php print $anno;?>"><?php print $anno;?></option><?php
        
    }?>
    </select>
    <br/>
    <div id="div_eventi">
    </div>
    <div id="testo_evento">
    </div>
    </body>
    </html>
    test9369b.php
    Codice PHP:
    <?php
    //---- controllo il valore del parametro "anno"
    if (!isset($_POST['anno']))
    {
        
    //---- parametro non è stato trasmesso esco !
        
    print "";
        die();
    }

    $anno_eventi $_POST['anno'];
    //---- Controllo se valore numerico
    if (!is_numeric($anno_eventi)) {
        
    //---- dato non numerico esco !
        
    print "";
        die();    
    }

    $bdd = new PDO('mysql:host=127.0.0.1; dbname=tests','root','', array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,PDO::MYSQL_ATTR_LOCAL_INFILE => true));

    //------ Lista degli eventi
    $query  "SELECT * FROM eventi where anno = $anno_eventi order by anno, id";

    $sth    $bdd->prepare($query);
    $sth->execute();?>
    <select id="eventi" onchange="testoEvento(this.value)"><?php
    while (list($anno,$id,$evento) = $sth->fetch(PDO::FETCH_NUM)) 
    {
    ?>
        <option value="<?php print "evento_".$anno."_".$id;?>"><?php print $evento;?></option><?php
    }
    ?>
    </select>
    test9369c.php
    Codice PHP:
    <?php
    //---- controllo il valore del parametro "id"
    if (!isset($_POST['id']))
    {
        
    //---- parametro non è stato trasmesso esco !
        
    print "";
        die();
    }
    //---- id ha la struttura seguente evento + _ + anno evento + _ + id
    $id          $_POST['id'];
    $array       explode('_',$id);
    if (
    count($array) != 3)
    {
        
    //---- array non ha 3 posti
        
    print "errore 1";
        die();    
    }
    $anno_eventi $array[1];
    $id_evento   $array[2];
    //---- Controllo se valore numerico
    if (!is_numeric($anno_eventi) || !is_numeric($id_evento)) {
        
    //---- dato non numerico esco !
        
    print "errore 2";
        die();    
    }

    $bdd = new PDO('mysql:host=127.0.0.1; dbname=tests','root','', array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,PDO::MYSQL_ATTR_LOCAL_INFILE => true));

    //------ Lista degli eventi
    $query  "SELECT * FROM eventi_testo where anno = $anno_eventi and id= $id_evento order by anno, id, riga";

    $sth    $bdd->prepare($query);
    $sth->execute();
    while (list(
    $anno,$id,$riga,$testo) = $sth->fetch(PDO::FETCH_NUM)) 
    {
    ?>
        <?php print $testo;?><br/><?php
    }
    ?>
    Allego anche la tabella eventi_testo struttura e dati da importare in phpMyAdmin. Cambiare l'estensione passandola da txt a sql.
    File allegati File allegati
    Ridatemi i miei 1000 posts persi !!!!
    Non serve a nulla ottimizzare qualcosa che non funziona.
    Cerco il manuale dell'Olivetti LOGOS 80B - www.emmella.fr

Tag per questa discussione

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.