Visualizzazione dei risultati da 1 a 10 su 10

Discussione: switch ed if

  1. #1

    switch ed if

    come scritto da gm, riapro il topic poichè non ho ancora risolto,

    quindi vi prego rispondete solamente se avete consigli o aiuti...
    grazie

    Codice PHP:
    <?php
    $user
    =uc($_COOKIE["usNick"]);
                
    $myDb->connect();
                    
    $sql "SELECT * FROM yob_users WHERE username='$user'";
                    
    $result mysql_query($sql);        
                    
    $row mysql_fetch_array($result);
                
    $myDb->close();
                
    $rootmoney=$row["money"];
                
    $rootvisit=$row["visits"];
                
    $rootpaid=$row["paid"];
                    
    $myDb->connect();
                        
    $sqle "SELECT * FROM yob_config WHERE item='payment' and howmany='1'";
                        
    $resulte mysql_query($sqle);        
                        
    $rowe mysql_fetch_array($resulte);
                    
    $myDb->close();
                
    $price=$rowe["price"];
    $myDb->connect();
    $sqlvolte mysql_query ("SELECT * FROM yob_history WHERE user='$user'");
    $num_righe mysql_num_rows ($risultato);         
    $myDb->close();
    switch (
    $num_righe) {
    case 
    0:


                if ((
    $rootmoney 2) OR ($rootvisit 50)) {
    <
    tr>
    <
    td style="" class="botao_act0" this.style.color='#000000';" onmouseout="this.style.backgroundColor='';this.style.color='';" nowrap="nowrap">
    <span id="
    bt1">NON PUOI CONVERTIRE</span>

    <div class="
    botao_act0_2">Devi avere almeno $2.00 e 50 Visite!</div></td>
    </tr>
    <? }else{?>
    <tr>
    <td style="" class="
    botao_act" onmouseover="this.style.backgroundColor='#cfe5ff';this.style.color='#000000';" onmouseout="this.style.backgroundColor='';this.style.color='';" onclick="document.location.href='/convert.php';" nowrap="nowrap"><span id="bt1">CONVERTI</span>
    <div class="
    botao_act_2">Ora puoi convertire!</div></td>
    <? } ?>
      break;


    case 1:
                if ((
    $rootmoney < 5) OR ($rootvisit < 100)) {
    <tr>
    <td style="" class="
    botao_act0" this.style.color='#000000';" onmouseout="this.style.backgroundColor='';this.style.color='';" nowrap="nowrap">
    <
    span id="bt1">NON PUOI CONVERTIRE</span>

    <
    div class="botao_act0_2">Devi avere almeno $5.00 e 100 Visite!</div></td>
    </
    tr>
    <? }else{
    ?>
    <tr>
    <td style="" class="botao_act" onmouseover="this.style.backgroundColor='#cfe5ff';this.style.color='#000000';" onmouseout="this.style.backgroundColor='';this.style.color='';" onclick="document.location.href='/convert.php';" nowrap="nowrap"><span id="bt1">CONVERTI</span>
    <div class="botao_act_2">Ora puoi convertire!</div></td>
    <? ?>
      break;



    case 2:
                if (($rootmoney < 10) OR ($rootvisit < 200)) {
    <tr>
    <td style="" class="botao_act0" this.style.color='#000000';" onmouseout="this.style.backgroundColor='';this.style.color='';" nowrap="nowrap">
    <span id="bt1">NON PUOI CONVERTIRE</span>

    <div class="botao_act0_2">Devi avere almeno $10.00 e 200 Visite!</div></td>
    </tr>
    <? }else{?>
    <tr>
    <td style="" class="botao_act" onmouseover="this.style.backgroundColor='#cfe5ff';this.style.color='#000000';" onmouseout="this.style.backgroundColor='';this.style.color='';" onclick="document.location.href='/convert.php';" nowrap="nowrap"><span id="bt1">CONVERTI</span>
    <div class="botao_act_2">Ora puoi convertire!</div></td>
    <? ?>
      break;
    default:
    }
    ?>
    mettendo cosi il codice mi da errore:

    Codice PHP:
    Parse errorsyntax errorunexpected '<' in /home/buxfanta/public_html/myaccount.php on line 145 
    ovvero a questa riga:

    Codice PHP:
    144:            if (($rootmoney 2) OR ($rootvisit 50)) {
    145: <tr>
    146: <td style="" 

  2. #2
    Dopo { scrivi ?> ovvero:

    Codice PHP:
     if (($rootmoney 2) OR ($rootvisit 50)) { ?> 

  3. #3
    Utente di HTML.it L'avatar di luca200
    Registrato dal
    Apr 2002
    Messaggi
    4,120
    Quando inserisci html puro dovrai pur mettere il tag di chiusura di php

  4. #4
    Originariamente inviato da filippo.toso
    Dopo { scrivi ?> ovvero:

    Codice PHP:
     if (($rootmoney 2) OR ($rootvisit 50)) { ?> 
    errore:
    Codice PHP:
    Parse errorsyntax errorunexpected T_ELSE in /home/buxfanta/public_html/myaccount.php on line 162 
    ovvero questa riga:
    Codice PHP:
    <? }else{?>

  5. #5
    Guarda, il tuo codice è pieno di questi errori, quasi fosse stato scritto senza conoscere la sintassi base del PHP.

    Codice PHP:
    <?php
    $user
    =uc($_COOKIE["usNick"]);
                
    $myDb->connect();
                    
    $sql "SELECT * FROM yob_users WHERE username='$user'";
                    
    $result mysql_query($sql);        
                    
    $row mysql_fetch_array($result);
                
    $myDb->close();
                
    $rootmoney=$row["money"];
                
    $rootvisit=$row["visits"];
                
    $rootpaid=$row["paid"];
                    
    $myDb->connect();
                        
    $sqle "SELECT * FROM yob_config WHERE item='payment' and howmany='1'";
                        
    $resulte mysql_query($sqle);        
                        
    $rowe mysql_fetch_array($resulte);
                    
    $myDb->close();
                
    $price=$rowe["price"];
    $myDb->connect();
    $sqlvolte mysql_query ("SELECT * FROM yob_history WHERE user='$user'");
    $num_righe mysql_num_rows ($risultato);         
    $myDb->close();
    switch (
    $num_righe) {
    case 
    0:


                if ((
    $rootmoney 2) OR ($rootvisit 50)) { ?>
    <tr>
    <td style="" class="botao_act0" this.style.color='#000000';" onmouseout="this.style.backgroundColor='';this.style.color='';" nowrap="nowrap">
    <span id="bt1">NON PUOI CONVERTIRE</span>

    <div class="botao_act0_2">Devi avere almeno $2.00 e 50 Visite!</div></td>
    </tr>
    <?php }else{?>
    <tr>
    <td style="" class="botao_act" onmouseover="this.style.backgroundColor='#cfe5ff';this.style.color='#000000';" onmouseout="this.style.backgroundColor='';this.style.color='';" onclick="document.location.href='/convert.php';" nowrap="nowrap"><span id="bt1">CONVERTI</span>
    <div class="botao_act_2">Ora puoi convertire!</div></td>
    <?php 
      break;


    case 
    1:
                if ((
    $rootmoney 5) OR ($rootvisit 100)) { ?>
    <tr>
    <td style="" class="botao_act0" this.style.color='#000000';" onmouseout="this.style.backgroundColor='';this.style.color='';" nowrap="nowrap">
    <span id="bt1">NON PUOI CONVERTIRE</span>

    <div class="botao_act0_2">Devi avere almeno $5.00 e 100 Visite!</div></td>
    </tr>
    <?php }else{ ?>
    <tr>
    <td style="" class="botao_act" onmouseover="this.style.backgroundColor='#cfe5ff';this.style.color='#000000';" onmouseout="this.style.backgroundColor='';this.style.color='';" onclick="document.location.href='/convert.php';" nowrap="nowrap"><span id="bt1">CONVERTI</span>
    <div class="botao_act_2">Ora puoi convertire!</div></td>
    <?php 
      break;



    case 
    2:
                if ((
    $rootmoney 10) OR ($rootvisit 200)) { ?>
    <tr>
    <td style="" class="botao_act0" this.style.color='#000000';" onmouseout="this.style.backgroundColor='';this.style.color='';" nowrap="nowrap">
    <span id="bt1">NON PUOI CONVERTIRE</span>

    <div class="botao_act0_2">Devi avere almeno $10.00 e 200 Visite!</div></td>
    </tr>
    <?php }else{?>
    <tr>
    <td style="" class="botao_act" onmouseover="this.style.backgroundColor='#cfe5ff';this.style.color='#000000';" onmouseout="this.style.backgroundColor='';this.style.color='';" onclick="document.location.href='/convert.php';" nowrap="nowrap"><span id="bt1">CONVERTI</span>
    <div class="botao_act_2">Ora puoi convertire!</div></td>
    <?php 
      break;
    default:
    }
    ?>
    Questo codice a me non da un parse error, ma non è detto che funzioni come ti aspetti.

    EDIT: Ora utilizza solo il tag di apertura completo.

  6. #6
    Utente di HTML.it L'avatar di luca200
    Registrato dal
    Apr 2002
    Messaggi
    4,120
    Sicuro che il tuo php supporti i short open tag?
    Prova a sostituire i <? con <?php

  7. #7
    Originariamente inviato da filippo.toso
    Guarda, il tuo codice è pieno di questi errori, quasi fosse stato scritto senza conoscere la sintassi base del PHP.

    Codice PHP:
    <?php
    $user
    =uc($_COOKIE["usNick"]);
                
    $myDb->connect();
                    
    $sql "SELECT * FROM yob_users WHERE username='$user'";
                    
    $result mysql_query($sql);        
                    
    $row mysql_fetch_array($result);
                
    $myDb->close();
                
    $rootmoney=$row["money"];
                
    $rootvisit=$row["visits"];
                
    $rootpaid=$row["paid"];
                    
    $myDb->connect();
                        
    $sqle "SELECT * FROM yob_config WHERE item='payment' and howmany='1'";
                        
    $resulte mysql_query($sqle);        
                        
    $rowe mysql_fetch_array($resulte);
                    
    $myDb->close();
                
    $price=$rowe["price"];
    $myDb->connect();
    $sqlvolte mysql_query ("SELECT * FROM yob_history WHERE user='$user'");
    $num_righe mysql_num_rows ($risultato);         
    $myDb->close();
    switch (
    $num_righe) {
    case 
    0:


                if ((
    $rootmoney 2) OR ($rootvisit 50)) { ?>
    <tr>
    <td style="" class="botao_act0" this.style.color='#000000';" onmouseout="this.style.backgroundColor='';this.style.color='';" nowrap="nowrap">
    <span id="bt1">NON PUOI CONVERTIRE</span>

    <div class="botao_act0_2">Devi avere almeno $2.00 e 50 Visite!</div></td>
    </tr>
    <?php }else{?>
    <tr>
    <td style="" class="botao_act" onmouseover="this.style.backgroundColor='#cfe5ff';this.style.color='#000000';" onmouseout="this.style.backgroundColor='';this.style.color='';" onclick="document.location.href='/convert.php';" nowrap="nowrap"><span id="bt1">CONVERTI</span>
    <div class="botao_act_2">Ora puoi convertire!</div></td>
    <?php 
      break;


    case 
    1:
                if ((
    $rootmoney 5) OR ($rootvisit 100)) { ?>
    <tr>
    <td style="" class="botao_act0" this.style.color='#000000';" onmouseout="this.style.backgroundColor='';this.style.color='';" nowrap="nowrap">
    <span id="bt1">NON PUOI CONVERTIRE</span>

    <div class="botao_act0_2">Devi avere almeno $5.00 e 100 Visite!</div></td>
    </tr>
    <?php }else{ ?>
    <tr>
    <td style="" class="botao_act" onmouseover="this.style.backgroundColor='#cfe5ff';this.style.color='#000000';" onmouseout="this.style.backgroundColor='';this.style.color='';" onclick="document.location.href='/convert.php';" nowrap="nowrap"><span id="bt1">CONVERTI</span>
    <div class="botao_act_2">Ora puoi convertire!</div></td>
    <?php 
      break;



    case 
    2:
                if ((
    $rootmoney 10) OR ($rootvisit 200)) { ?>
    <tr>
    <td style="" class="botao_act0" this.style.color='#000000';" onmouseout="this.style.backgroundColor='';this.style.color='';" nowrap="nowrap">
    <span id="bt1">NON PUOI CONVERTIRE</span>

    <div class="botao_act0_2">Devi avere almeno $10.00 e 200 Visite!</div></td>
    </tr>
    <?php }else{?>
    <tr>
    <td style="" class="botao_act" onmouseover="this.style.backgroundColor='#cfe5ff';this.style.color='#000000';" onmouseout="this.style.backgroundColor='';this.style.color='';" onclick="document.location.href='/convert.php';" nowrap="nowrap"><span id="bt1">CONVERTI</span>
    <div class="botao_act_2">Ora puoi convertire!</div></td>
    <?php 
      break;
    default:
    }
    ?>
    Questo codice a me non da un parse error, ma non è detto che funzioni come ti aspetti.

    EDIT: Ora utilizza solo il tag di apertura completo.

    ti ringrazio funziona,
    però come faccio a fare che quando il numero delle righe è maggiore di 2?

    cioè invece di "case 2" dovrei farlo maggiore di 2...


  8. #8
    Prendi quello che hai scritto in case 2 e spostalo in default all'interno di un if ($num_righe > 2)

  9. #9
    Utente di HTML.it L'avatar di luca200
    Registrato dal
    Apr 2002
    Messaggi
    4,120
    Originariamente inviato da clickfantasy
    ti ringrazio funziona,
    però come faccio a fare che quando il numero delle righe è maggiore di 2?

    cioè invece di "case 2" dovrei farlo maggiore di 2...

    > 2 o >= 2 ?? :master:
    Perché se è solo >2, il valore 2 rimane fuori e vorrei sapere come lo gestisci.
    Se invece è >=2, è sufficiente togliere il case 2 e spostare il codice sotto default, che è poi quello che ti avevo postato io nell'altro thread

  10. #10
    risolto mettendo il codice nel default come suggerito...

    grazie a tutti per la vostra pazienza ^_^

    saluti

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.