Visualizzazione dei risultati da 1 a 7 su 7
  1. #1
    Utente di HTML.it
    Registrato dal
    Feb 2006
    Messaggi
    495

    concatenare stringhe con or

    ciao!
    devo concatenare delle stringhe e metterle in or.
    Il risultato è che $string_sql = "DT OR PR OR DU"
    Io ho fatto:

    $string_sql = '';

    if($atto_dt=='DT')
    {
    $string_sql_dt = 'DT';
    }
    if($atto_pr=='PR')
    {
    $string_sql_pr = 'PR';
    }
    if($atto_du=='DU')
    {
    $string_sql_du = 'DU';
    }

    $string_sql .= ($string_sql_dt || $string_sql_pr || $string_sql_du );

    Cosa non va?
    Grazie!

  2. #2
    Il fatto che utilizzi l'operatore || di PHP quando invece dovresti concatenare le variabili come stringhe.

  3. #3
    Utente di HTML.it
    Registrato dal
    Feb 2006
    Messaggi
    495
    quindi per ottenere
    $string_sql = "DT OR RP OR DU"

    dovrei fare:

    $string_sql = $string_sql_dt . " OR ". $string_sql_pr . " OR ". $string_sql_du ;

    manco cosi però va bene..

  4. #4

  5. #5
    Utente di HTML.it
    Registrato dal
    Feb 2006
    Messaggi
    495
    Ok, sbagliavo io..
    ora però ho un'altra domanda:
    Se non ho tuuti i valori della stringa mi restano degli or in mezzo che non servono a nulla. Quindi ho pensato che dovrei fare un controllo del tipo:

    if(($string_sql_dt != '')&&($string_sql_pr != ''))
    {
    $string_sql = $string_sql_dt . " OR ". $string_sql_pr;
    }
    else if(...)

    dovrei farlo per tutti i casi. sai suggerirmi un modo più veloce?

  6. #6
    Studiati questo codice:

    Codice PHP:
    <?php 

    $atto_dt 
    '';
    $atto_pr 'PR';
    $atto_du 'DU';

    $string_sql '';
    $join '';

    if (
    $atto_dt == 'DT') {
        
    $string_sql .= $join 'DT';
        
    $join ' OR ';
    }
    if (
    $atto_pr == 'PR') {
        
    $string_sql .= $join 'PR';
        
    $join ' OR ';
    }
    if (
    $atto_du == 'DU') {
        
    $string_sql .= $join 'DU';
        
    $join ' OR ';
    }

    print(
    $string_sql);

    ?>

  7. #7
    Utente di HTML.it
    Registrato dal
    Feb 2006
    Messaggi
    495
    ti ringrazio tanto!!riesci sempre a darmi una mano!!

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.