[PHP/MYSQL] Echo dans un echo

Résolu
Bonjour,
Je cherche a mettre des données mysql dans un tableau tout en réalisant des if dans ce tableau.
Donc logiquement j'ai fait quelque chose comme sa :

$base = mysql_connect ('xxx', 'xxx', 'xxx'); 
mysql_select_db ('xxx', $base) ;  
$sql = 'SELECT * FROM ORDER BY id DESC';   
$req = mysql_query($sql) or die('Erreur SQL !<br />'.$sql.'<br />'.mysql_error());  
while ($data = mysql_fetch_array($req)) {  
echo '<tr><td>'.$data['Id'].'</td>'; 
echo '<td>'.$data['Name'].'</td>'; 
echo '<td>'.$data['Status'].'</td>'; 
echo '<td>'.$data['Type'].''; 
echo if($data['Type'] == Type1) { echo'(Warning)'; } else { };      <- ligne 52
echo '</td></tr>'; } 
mysql_free_result ($req); 


Sauf que non, sa marche pas, je comprend absolument pas pourquoi.
Et j'ai droit a un "Parse error: syntax error, unexpected T_IF in /public_html/xx/index.php on line 52"

Merci d'avance

4 réponses

  1. Salut,

    En fait... Pas de "echo" devant ton if.
    0
    1. Merci.
      0
      1. De rien ;)
        0
    2. echo if($data['Type'] == Type1) { echo'(Warning)'; } else { };
      echo if($data['Type'] == "Type1") { echo'(Warning)'; } else { };
      0
      1. dans des cas comme çà, l'opérateur ternaire est pratique :

        echo ($data['Type'] == "Type1")?'Warning':'';
        0
        1. C'est juste illisible, mais pourquoi pas
          0