Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    explode, foreach, mysql

    Salve a tutti,
    Ho una variabile $test che contiene degli id, vorrei stampare "nome-ok" se l'id è presente nel database e "nome-ko" se non è presente in esso...
    Sto facendo i test per "nome-ko" ma non mi funziona, mi stampa tutti gli id nel db...
    In questo esempio dovrei stampare tutti gli id, esclusi 1 e 2.
    Mi date un aiutino?
    Grazie

    codice:
    $test="1-2"
    $dj = explode("-", $test);
    foreach ($dj as $con) {
    
    $query = mysql_query("SELECT id,nome FROM $db_table1 where id!= ".$con." order by nome");
    //tutti gli id tranne 1 e 2
    
    
    while($row = mysql_fetch_array($query)) {
    
    echo $row['nome']."-ko
    ";
    
    }
    }
    What is the |\/|atrix?

  2. #2
    Il foreach scorre l'array uno ad uno e quindi con id-1 ti pesca fuori id-2 e con id-2 tira fuori id-1

    potresti fare una variabile multivalore del tipo:
    codice:
    $test = '1, 2, 3';
    
    $query = mysql_query("SELECT id, nome 
                          FROM $db_table1 
                          where id NOT IN($test)
                          order by nome");


    Il silenzio è spesso la cosa migliore. Pensa ... è gratis.

  3. #3
    Perfetto!!!
    Grazie mille!
    What is the |\/|atrix?

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 © 2024 vBulletin Solutions, Inc. All rights reserved.