Page 1 sur 1
Condition multiple sur un lien
Posté : 23 juin 2005, 18:20
par Gico
Bonjour
j'ai un lien conditionnel qui ressemble à ça :
<?php echo($row_rsMotsclefs['catID']== "14" ? "fiche2" : "fiche1"); ?>.php
mais je voudrais valider la condition sur plusieurs valeures :
ex si :$row_rsMotsclefs['catID']== "14" ou "15" ou "16"...alors ouvrir fiche2.php sinon ouvrir fiche1.php. Le OR ne fonctionne pas ici...
merci du coup de main
Posté : 23 juin 2005, 18:39
par benjamin
Pour plusieur valeur tu peux fair :
<?php
if (($row_rsMotsclefs['catID'] == "14")&&($row_rsMotsclefs['catID'] == "15")){ //si $row_rsMotsclefs['catID'] est eguale à 14 et 15
echo($row_rsMotsclefs['catID']== "14" ? "fiche2" : "fiche1");
}
if (($row_rsMotsclefs['catID'] >= "14")&&($row_rsMotsclefs['catID'] <= "17")){ //si $row_rsMotsclefs['catID'] est saperieur à 14 et inferieur à 17
echo($row_rsMotsclefs['catID']== "14" ? "fiche2" : "fiche1");
}
if (($row_rsMotsclefs['catID'] == "14")||($row_rsMotsclefs['catID'] == "15")){ //si $row_rsMotsclefs['catID'] et eguale à 14 ou 15
echo($row_rsMotsclefs['catID']== "14" ? "fiche2" : "fiche1");
}
if (($row_rsMotsclefs['catID'] >= "14")||($row_rsMotsclefs['catID'] <= "17")){ //si $row_rsMotsclefs['catID'] est saperieur à 14 ou inferieur à 17
echo($row_rsMotsclefs['catID']== "14" ? "fiche2" : "fiche1");
}
?>
merci
Posté : 23 juin 2005, 21:02
par Gico
Ok ça fonctionne, merci. Et merci pour la mise en forme pédagogique.
Posté : 23 juin 2005, 21:13
par pjl
Pour ton exemple, si tu as des valeurs biens définies, je verrais plutot un switch.
http://fr.php.net/manual/fr/control-str ... switch.php