• User Attivo

    problema legame tra id

    ciao a tutti ho un grande problema:

    io ho una tabella dalla quale riesco a prendere i miei 2 id che chiamo A B (sono gli idlista).

    poi in un altra tabella che si chiama include ho la seguente situazione:

    all'id A corrispondo 3 id che chiamo a,b,c

    all'id B corrispondo 2 id che chiamo d,f

    ora il problema è che non riesco a prendere e quindi stampare gli id a,b,c,d,f

    come posso fare.

    posto il codice sino a dove sono arrivato, cioè ho trovato gli idlista

    
    $query1 = "SELECT idlista FROM definisce where idutente = '$idutente'"; 
    $result = mysql_query($query1) or die("Errore nella query1:".mysql_error());
    $numerorighe = mysql_num_rows($result);
    
    
    for($x=0; $x<$numerorighe; $x++){
    
        $riga = mysql_fetch_array($result); 
        $idlista = $riga['idlista'];        
    
    
    }
    
    
    

  • User Attivo

    non ho capito :mmm:


  • User Attivo

    CIAO SPACCIOMAN, SN RIUSCITO A RISOVERE USANDO UN CICLO FOR E UN FOREACH.

    L'UNICA COSA CHE NON RIESCO A FARE è che se ho

    $row = mysql_fetch_array($result1);

    come faccio a scriverlo come vettore del tipo:

    $liste = array('152','153');


  • Super User

    ciao, puoi fare così:

    while($row=mysql_fetch_array($result1))
    array_push($liste,$row['nome del campo']);

    :ciauz:


  • User Attivo

    ciao Tymba e buona domenica.

    allora il problema è il seguente: $riga = array ('157','158'); ottengo tutti gli idutente che sn associati a quelle id che sn 157 e 158.ho fatto cosi x fare una prova e vedere se il codice del foreach funzionava e va ok.

    però li devo avere in $riga = mysql_fetch_array($result1); però non mi va cosi:

    come posso fare, l soluzione che hai scritto con il while non l'ho capita.

    
    
    <?php
    //Includo i file per la connessione
    //e per la verifica Utente
    require_once('connessione.php');
    require_once('verificalogin.php');
    
    ?>
    
    <html>
    <head>
    </head>
    
    <body>
    <?php
    if(IsSet($_SESSION['utenteM'])){
    }else
    {
        echo "errore";
    }
    
    
    
    $user=$_SESSION['utenteM'][0];
    
    
    
        $query1 = "SELECT * FROM utente WHERE username = '$user'"; 
         $result1 = mysql_query($query1) or die("Errore nella query1:".mysql_error());  
          $row = mysql_fetch_array($result1); 
         $idutente = $row['idutente'];
         
         //echo $idutente ;
    
    
          $query1 = "SELECT * FROM definisce WHERE idutente = '$idutente'"; 
         $result1 = mysql_query($query1) or die("Errore nella query1:".mysql_error()); 
         $numerorighe = mysql_num_rows($result1);
         
        //echo $numerorighe;
         
    for($x=0; $x<$numerorighe; $x++){
                                    
         $riga = mysql_fetch_array($result1); 
        //$idliste = $riga['idlista'];
        //    echo $idliste;
    
    
    
    //$riga = array ('157','158');
         
    
    foreach ($riga as $value) {
    
        $query2 = "SELECT * FROM include WHERE idlista = '$value'"; 
         $result1 = mysql_query($query2) or die("Errore nella query2:".mysql_error()); 
        $numerorighe = mysql_num_rows($result1);
        
        echo "<br>$numerorighe";
        
        for($x=0; $x<=$numerorighe; $x++){
                                
         $resrow = mysql_fetch_row($result1);
         $idutente=$resrow['1'];
         
         echo  "<br>$idutente";
        
        
         
         }
         
        
    }}
    
    
    ?>
    
    
    </body>
    </html>