Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 17

Discussione: condizione else

  1. #1

    condizione else

    Ciao,

    Il codice
    Codice PHP:
    $query1 "SELECT * FROM ordini where ID = '$id' ORDER BY prodotto";
                    
    $dati1 mysql_query($query1$DB); 
                    while(
    $row1 mysql_fetch_array($dati1)) 
    if(
    $row1[2] ==""){
           echo
    "<span class=togli>Nessun prodotto selezionato!</span>

    "
    ;
    }else{
           echo
    "<td width=40% align left class=testounico>$row1[2]</td>
           <td width=20% align=right class=testounico>
    $row1[3] euro</td>
           <td width=20% align=right class=testounico>
    $row1[4]</td>
           <td width=30% align=right class=testounico>
    $row1[5] euro</td>";

    Ma perchè cavolo se ($row1[2] =="") non mi stampa il messaggio Nessun prodotto selezionato!
    Mentre accetta perfettamente la seconda condizione??? :master:

  2. #2
    E' errata la condizione if

    codice:
    $query1 = "SELECT * FROM ordini where ID = '$id' ORDER BY prodotto";
    $dati1 = mysql_query($query1, $DB); 
    while($row1 = mysql_fetch_array($dati1)) 
    if($row1 == "")
    {
         echo"<span class=togli>Nessun prodotto selezionato!</span>
    
    ";
    }
    else
    {
    
      //Altro codice
    
    }
    durante il ciclo while... $row1 in ogni ciclo assume i valori di ciascun record della tabella ordini nel DB
    Sei nella tabella ordini ci sono 5 record il ciclo while verra eseguito 5 volte.

    Fammi sapere!

    [EDIT BY GM]
    Al prossimo spam segnalo direttamente all'admin

  3. #3
    Non funzia.

  4. #4
    stampa a video un po di variabili per provare a risalire al problema
    Codice PHP:
    $query1 "SELECT * FROM ordini where ID = '$id' ORDER BY prodotto";
    echo 
    $query1."\n";
    $dati1 mysql_query($query1$DB) or die(mysql_error()); 
    while(
    $row1 mysql_fetch_array($dati1)){ 
        
    var_dump($row1);
        if(
    $row1[2] ==""){
            echo
    "<span class=togli>Nessun prodotto selezionato!</span>

    "
    ;
        }else{
                echo
    "<td width=40% align left class=testounico>$row1[2]</td>
           <td width=20% align=right class=testounico>
    $row1[3] euro</td>
           <td width=20% align=right class=testounico>
    $row1[4]</td>
           <td width=30% align=right class=testounico>
    $row1[5] euro</td>";
        }


    [edit]visto meglio .. immagino che l'id sia univoco per cui il while($row1 = mysql_fetch_array($dati1)) è tra l'altro superfluo

  5. #5
    Le variabili sono giuste. Le passa tutte
    Ho provato così:
    Codice PHP:
    $query1 "SELECT * FROM ordini where ID = '$id' ORDER BY prodotto";
                    
    $dati1 mysql_query($query1$DB);
                    while(
    $row1 mysql_fetch_array($dati1))
    if(
    $row1[2] ==""){
           echo
    "<td width=40% align left class=testounico>$row1[2]</td>
           <td width=20% align=right class=testounico>
    $row1[3] euro</td>
           <td width=20% align=right class=testounico>
    $row1[4]</td>
           <td width=30% align=right class=testounico>
    $row1[5] euro</td>";
    }else{
    echo
    "<span class=togli>Nessun prodotto selezionato!</span>

    "
    ;

    Adesso succede il contrario:
    Se ($row1[2] =="") mi stampa il messaggio Nessun prodotto selezionato!
    Praticamente accetta solo ed esclusivamente la seconda condizione!!

  6. #6
    Adesso ho provato così:
    Codice PHP:
    $query1 "SELECT * FROM ordini where ID = '$id' ORDER BY prodotto";
                    
    $dati1 mysql_query($query1$DB);
                    while(
    $row1 mysql_fetch_array($dati1))
    if(
    $row1[2] ==""){
    echo
    "<span class=togli>Nessun prodotto selezionato!</span>

    "
    ;
           }else{
    echo
    "";

    $row1[2]=="" e non stampa niente.
    Evidentemente $row1[2] non è eguale a niente!!
    Proverò a verificare sulle impostazioni del DB.

  7. #7
    var_dump($row1);
    avevo messo anche questo nel while, così vedi cosa estrai dal db

  8. #8
    Utente di HTML.it L'avatar di luca200
    Registrato dal
    Apr 2002
    Messaggi
    4,120
    Scusa ma cosa accidente ci dovrebbe essere in questo $row1[2]??

  9. #9

    Spam not allowed

    cmq l'istruzione:
    echo"<span class=togli>Nessun prodotto selezionato!</span>

    ";

    la esegue solo se il campo "2" della riga è vuoto

    per $row1[2] si indica il campo "2" della riga.....

    [EDIT BY GM]
    Al prossimo spam segnalo direttamente all'admin

  10. #10
    Eyescream ecco il tutto
    Codice PHP:
    $query1 "SELECT * FROM ordini where ID = '$PHPSESSID' ORDER BY prodotto";
    echo 
    $query1."\n";
    $dati1 mysql_query($query1$DB) or die(mysql_error());
    while(
    $row1 mysql_fetch_array($dati1)){
        
    var_dump($row1);
        if(
    $row1[2] ==""){
            echo
    "<span class=togli>Nessun prodotto selezionato!</span>

    "
    ;
        }else{
                echo
    "<td width=40% align left class=testounico>$row1[2]</td>
           <td width=20% align=right class=testounico>
    $row1[3] euro</td>
           <td width=20% align=right class=testounico>
    $row1[4]</td>
           <td width=30% align=right class=testounico>
    $row1[5] euro</td>";
        }


    SELECT * FROM ordini where ID = 'e7a1aa971908ebf2bef9d58707c0d701' ORDER BY prodotto array(14) { [0]=> string(3) "836" ["idm"]=> string(3) "836" [1]=> string(32) "e7a1aa971908ebf2bef9d58707c0d701" ["ID"]=> string(32) "e7a1aa971908ebf2bef9d58707c0d701" [2]=> string(10) "finocchina" ["prodotto"]=> string(10) "finocchina" [3]=> string(1) "3" ["quantita"]=> string(1) "3" [4]=> string(6) " al kg" ["modalita"]=> string(6) " al kg" [5]=> string(4) "2.40" ["totale"]=> string(4) "2.40" [6]=> string(4) "0.80" ["prezzo"]=> string(4) "0.80" }
    come vedi è tutto ok!

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.