Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
2360 connectés 

  FORUM HardWare.fr
  Programmation
  PHP

  afficher les publications des membres

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

afficher les publications des membres

n°2254419
sarah miss​a
Posté le 28-03-2015 à 16:30:18  profilanswer
 

salut
 
j'essaye de créer un espace membre pour un projet d’étude,et j'ai un problème au niveau de l’affichage des publications des membres
 
j'ai crée 2 tables sql une table_user ( contenant le pseudo ,mot de passe ) et table_publication(contient les statuts ,images,fichiers que l'utilisateur publie )  
 
je veux afficher toutes les publication des membres  
 
Le problème c'est que ça m'affiche même les champs NULL  (ex: un user n'a pas publié d'image mais ça affiche un espace vide quand même )  
 
Avez-vous une idée sur la source du problème ?  
voici le code

Code :
  1. <?php
  2. session_start();
  3. // on vérifie toujours qu'il s'agit d'un membre qui est connecté
  4. if (!isset($_SESSION['pseudo'])) {
  5. // si ce n'est pas le cas, on le redirige vers l'accueil
  6. header ('Location: connexion.php');
  7. exit();
  8. }
  9. ?>
  10. <html>
  11. <head>
  12. <title>space</title>
  13. <meta charset="utf-8"/>
  14.     <link rel="stylesheet" href="style.css" />
  15. </head>
  16. <body>
  17. Bienvenue <?php echo htmlentities(trim($_SESSION['pseudo'])); ?> !<br />
  18. <?php
  19. try
  20. {
  21. $bdd = new PDO('mysql:host=localhost;dbname=edic', 'root', '',
  22.                array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
  23. }catch(Exception $e)
  24. {
  25. die('Erreur : '.$e->getMessage());
  26. }
  27. // on prépare une requete SQL cherchant les status,fichiers,images,des membres
  28. $req = $bdd->query ('SELECT user.pseudo ,id_publier,statuts,images,fichiers,date_publication
  29.                       FROM user INNER JOIN publier ON publier.id_auteur = user.user_id ORDER BY date_publication DESC  ' );
  30. $num_rows = $req->rowCount();
  31. if ($num_rows == 0) {
  32. echo "il n'existe aucune publication";
  33. }
  34. else {
  35. // si on a des status,images,fichiers on les affiche
  36.    
  37.     <section style="height:auto;">
  38.     <div id="tablo">
  39.     <?php
  40.       echo $num_rows." publications<br/><br/>";
  41. while ($data = $req->fetch()) {
  42.         $id = $data['id_publier'];
  43.        
  44.        ?>
  45.    
  46. <table style="margin-top:10px">
  47.     <tr><td class="c"> <span class="pseudo"><?php echo stripslashes(htmlentities(trim($data['pseudo']))); ?></span></td></tr>
  48.     <tr><td class="c" style="height: 50px;">
  49.     <span class="msg"><?php echo (stripslashes(htmlentities(trim($data['statuts'])))); ?></span></td></tr>
  50.     <tr><td class="c"><span class="date"><?php echo $data['date_publication']; ?></span></td> </tr>
  51. </table>
  52. <table style="margin-top:10px">
  53.     <tr> <td class="c"> <span class="pseudo"><?php echo stripslashes(htmlentities(trim($data['pseudo']))); ?></span>
  54.     <tr> <td class="c" style="height: 50px;">
  55.      
  56.     <p><span class="msg"> <?php echo  "<img src='".$data['images']."' width='260' height='270' />"; ?></p></span>
  57.     </td></tr>
  58.     <tr><td class="c"><span class="date"><?php echo $data['date_publication']; ?></span></td> </tr>
  59.                
  60. </table>
  61. <table style="margin-top:10px">
  62.     <tr> <td class="c"> <span class="pseudo"><?php echo stripslashes(htmlentities(trim($data['pseudo']))); ?></span></td></tr>
  63.                
  64.     <tr> <td class="c" style="height: 50px;"><p><img src="fiche.png" style=" width:55px; hight:45px;"/>
  65.              
  66.         <?php echo"<a href='telecharger.php?id_publier=$id' style='margin-left:20px'>Télécharger</a><br/>" ?>
  67.            
  68.         <span class="msg"> <?php echo (stripslashes(htmlentities(trim($data['fichiers'])))); ?></p></span></td></tr>
  69.        
  70.         <tr><td class="c"><span class="date"><?php echo $data['date_publication']; ?></span></td> </tr>
  71. </table>
  72.      
  73.        
  74.        
  75.                  
  76.        
  77.      
  78. <?php
  79. }
  80. }
  81.      
  82.    
  83. $req->closeCursor();
  84. ?>
  85. </div>
  86. </section>
  87. <br /><a href="publier_statuts.php">Publier un statut </a>
  88. <br /><a href="publier_fichiers.php">Publier un fichier </a>
  89. <br /><a href="publier_images.php">Publier une image </a>
  90. <br/><a href="deconnexion.php">Déconnexion</a>
  91. </body>
  92. </html>


 
Merci pour votre aide

mood
Publicité
Posté le 28-03-2015 à 16:30:18  profilanswer
 

n°2255043
tompouss
Petit chat
Posté le 05-04-2015 à 20:44:37  profilanswer
 

Normalement si tu rajoutes une clause WHERE différent de NULL pour les publications ça devrait donner le résultat attendu.
Attention tu ne peux pas la mettre n'importe où.
Cherche un peu sur le net car je ne connais pas la syntaxe par coeur


---------------
collectionneur de pâtes thermiques

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  PHP

  afficher les publications des membres

 

Sujets relatifs
Afficher le nouveau enregistrement dans la liste.Afficher texte si l'URL contient un mot
Besoin d'afficher le contenu de la catégorie "2"Afficher/Masquer éléments DIV en javascript
Cacher/Afficher en Javascript[Excel] Afficher un bouton sous condition : Résolu
Afficher la ligne d'une table après avoir choisi son ID dans une listecopy en batch , afficher progression en %
Afficher bannière et ses boutons en allant la chercher sur autre pagePHP afficher un champ Multiple-select
Plus de sujets relatifs à : afficher les publications des membres


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR