Condition php

Résolu
phoenixgreg Messages postés 77 Date d'inscription mardi 17 novembre 2009 Statut Membre Dernière intervention 18 août 2015 - 3 mars 2012 à 20:55
phoenixgreg Messages postés 77 Date d'inscription mardi 17 novembre 2009 Statut Membre Dernière intervention 18 août 2015 - 4 mars 2012 à 00:03
Bonsoir all !

Besoin d'un petit coup de main pour une simple condition en php.

Je fais un blog et j'aimerai, quand un article ne comporte pas de commentaires, qu'il affiche 'Aucun commentaire pour le moment' et inversement 'rien'. Avec le code que j'ai en ce moment rien ne s'affiche, commentaires ou pas. J'en appel à vos lumières !

Merci ;)

Voilà le code :

Code PHP :

 $req $bdd->prepare('SELECT auteur, commentaire, DATE_FORMAT(date_commentaire, \'%d/%m/%Y à %Hh%imin%ss\') AS date_commentaire_fr FROM commentaires WHERE id_billet ? ORDER BY date_commentaire');
    $req->execute(array($_GET['billet']));
    
    while ($donnees = $req->fetch())
    {
    ?>
    <?php echo htmlspecialchars($donnees['auteur']); ?> le <?php echo $donnees['date_commentaire_fr']; ?>


    <?php echo nl2br(htmlspecialchars($donnees['commentaire'])); ?>


    <?php
    } 
    
    if(empty($req)) {
      echo 'Aucun commentaire pour le moment';
      }

    else{
      echo '';
      }
    $req->closeCursor();

2 réponses

TychoBrahe Messages postés 1309 Date d'inscription samedi 31 janvier 2009 Statut Membre Dernière intervention 5 juin 2013 12
3 mars 2012 à 22:44
Salut,

Utilises rowCount().
3
phoenixgreg Messages postés 77 Date d'inscription mardi 17 novembre 2009 Statut Membre Dernière intervention 18 août 2015
4 mars 2012 à 00:03
Ouais pourquoi pas ! Je te tiens au jus, thx
0
Rejoignez-nous