Affichage des publications des utilisateurs (dans un espace membres)
Posté : 28 mars 2015, 18:39
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 )
j'ai essayé le condition if($data['fichiers']=!NULL) mais ça marche toujours pas
Avez-vous une idée sur la source du problème ?
voici le code
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 )
j'ai essayé le condition if($data['fichiers']=!NULL) mais ça marche toujours pas
Avez-vous une idée sur la source du problème ?
voici le code
<?php
session_start();
// on vérifie toujours qu'il s'agit d'un membre qui est connecté
if (!isset($_SESSION['pseudo'])) {
// si ce n'est pas le cas, on le redirige vers l'accueil
header ('Location: connexion.php');
exit();
}
?>
<html>
<head>
<title>space</title>
<meta charset="utf-8"/>
<link rel="stylesheet" href="style.css" />
</head>
<body>
Bienvenue <?php echo htmlentities(trim($_SESSION['pseudo'])); ?> !<br />
<?php
try
{
$bdd = new PDO('mysql:host=localhost;dbname=edic', 'root', '',
array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
}catch(Exception $e)
{
die('Erreur : '.$e->getMessage());
}
// on prépare une requete SQL cherchant les status,fichiers,images,des membres
$req = $bdd->query ("SELECT user.pseudo ,id_publier,statuts,images,fichiers,date_publication
FROM user INNER JOIN publier ON publier.id_auteur = user.user_id
ORDER BY date_publication DESC " );
$num_rows = $req->rowCount();
if ($num_rows == 0) {
echo "il n'existe aucune publication";
}
else {
// si on a des status,images,fichiers on les affiche
?>
<section style="height:auto;">
<div id="tablo">
<?php
echo $num_rows." publications<br/><br/>";
while ($data = $req->fetch()) {
$id = $data['id_publier'];
?>
<table style="margin-top:10px">
<tr><td class="c"> <span class="pseudo"><?php echo stripslashes(htmlentities(trim($data['pseudo']))); ?></span></td></tr>
<tr><td class="c" style="height: 50px;">
<span class="msg"><?php if($data['statuts']=!NULL) {echo (stripslashes(htmlentities(trim($data['statuts']))));} ?></span></td></tr>
<tr><td class="c"><span class="date"><?php echo $data['date_publication']; ?></span></td> </tr>
</table>
<table style="margin-top:10px">
<tr> <td class="c"> <span class="pseudo"><?php echo stripslashes(htmlentities(trim($data['pseudo']))); ?></span>
<tr> <td class="c" style="height: 50px;">
<p><span class="msg"> <?php if($data['images']=!NULL){ echo "<img src='".$data['images']."' width='260' height='270' />";} ?></p></span>
</td></tr>
<tr><td class="c"><span class="date"><?php echo $data['date_publication']; ?></span></td> </tr>
</table>
<table style="margin-top:10px">
<tr> <td class="c"> <span class="pseudo"><?php echo stripslashes(htmlentities(trim($data['pseudo']))); ?></span></td></tr>
<tr> <td class="c" style="height: 50px;"><p><img src="fiche.png" style=" width:55px; hight:45px;"/>
<?php echo"<a href='telecharger.php?id_publier=$id' style='margin-left:20px'>Télécharger</a><br/>" ?>
<span class="msg"> <?php if($data['fichiers']=!NULL) {echo (stripslashes(htmlentities(trim($data['fichiers']))));} ?></p></span></td></tr>
<tr><td class="c"><span class="date"><?php echo $data['date_publication']; ?></span></td> </tr>
</table>
<?php
}
}
$req->closeCursor();
?>
</div>
</section>
<br /><a href="publier_statuts.php">Publier un statut </a>
<br /><a href="publier_fichiers.php">Publier un fichier </a>
<br /><a href="publier_images.php">Publier une image </a>
<br/><a href="deconnexion.php">Déconnexion</a>
</body>
</html>
Merci pour votre aide c'est vraiment très important