par
nico44530 » 03 avr. 2013, 15:26
Bonjour,
J'ai un problème avec mon système de commentaires :
Quand je post un seul commentaire (manuellement sur phpmyadmin), le résultat affiche deux mêmes commentaires postés par les deux seuls membres inscrits.
Par exemple, j'écris "Bonjour" dans le post ayant l'id "1", le résultat affichera 2 fois "Bonjour" :
- Une fois c'est moi qui l'écrit
- Une autre fois, c'est l'autre membre
Je crois qu'il y a des gros changements à faire dans mon code :
Il y a que 2 requêtes : une pour lister les news, et l'autre pour lister les commentaires liés au news.
J'ai 3 tables :
wa_communaute : id AI, pseudo, pass, mail
wa_comment : id_com AI, membre_id (l'id du membre qui post), msg_com, post_id (l'id du post lié au commentaire), date
wa_mur : id_post AI, id_membre (l'id du membre qui post la news), poster (la new), date_heure
Comment faire pour relier tout ça, et joindre les tables, pour que chaque membre puisse commenter une new sans double commentaire ou autre erreur.
Pour la requête qui affiche les news, je sais comment faire. Je demande de l'aide pour les commentaires, j'ai du mal avec les jointures
<div id="mur-principal">
<ul>
<?php
$req = $connect->query('SELECT * FROM wa_mur, wa_communaute WHERE id_membre = id ORDER BY date_heure LIMIT 0,10');
$com = $connect->prepare('SELECT * FROM wa_comment JOIN wa_communaute ON membre_id = :id ORDER BY date DESC;');
while($data = $req->fetch()) { ?>
<li class="user-item" style="float: left;padding: 13px 10px 10px;width: 460px;border-top: 1px solid #cecece;word-wrap: break-word;">
<div class="user-avatar float-l" style="margin-right: 10px;">
<a href="/<?php echo htmlentities(trim($data['pseudo'])); ?>"><img src="../img/upload/<?php echo htmlentities(trim($data['id'])); ?>-mini.png" width="50" height="50" alt="" /></a>
</div>
<div class="user-title" style="margin-bottom: 5px;font-weight: bold;">
<a href="/<?php echo htmlentities(trim($data['pseudo'])); ?>" style="color: #005B83;"><?php echo htmlentities(trim($data['prenom'])); ?> <?php echo htmlentities(trim($data['nom'])); ?></a>
</div>
<div class="user-content" style="margin-left: 60px;">
<p><?php echo nl2br(trim($data['poster'])); ?></p>
</div>
<div class="sub-userContent" style="margin-left: 60px;">
<div class="sub-userFooter" style="margin-top: 6px;">
<p class="size11" style="color: #777;"><a href="" class="sub-userFooter-link" style="color: #0D5085;">J'aime</a> - <a href="" class="sub-userFooter-link" style="color: #0D5085;">Commenter</a> - <?php echo getRelativeTime($data['date_heure']); ?></p>
</div>
<ul class="sub-userData" style="list-style-type: none;">
<li>
<i class="sub-userArrow" style="background: url(../img/top-sub-user.png);background-repeat: no-repeat;height: 5px;display: block;margin-top: 5px;margin-left: 60px;"></i>
</li>
<?php $com->execute(array('id' => $data['id']));
while($data_comm = $com->fetch()){ ?>
<li class="sub-userItem" style="background-color: #bebebe;margin: 0;padding: 4px;margin: 0 0 1px;min-height: 32px;">
<div class="user-avatarCom" style="float: left;padding: 0;margin: 0;">
<img style="margin-right: 4px;" src="../img/upload/<?php echo $data_comm['membre_id']; ?>-mini.png" width="32" height="32" alt="" />
</div>
<div class="sub-userCom" style="overflow: hidden;padding-left: 4px;">
<div>
<p class="size11">
<a href="/<?php echo htmlentities(trim($data_comm['pseudo'])); ?>" style="color: #005B83;">
<b><?php echo htmlentities(trim($data_comm['prenom'])); ?> <?php echo htmlentities(trim($data_comm['nom'])); ?></b></a>
<span> <?php echo nl2br(htmlspecialchars($data_comm['msg_com'])); ?></span>
</p>
</div>
<div>
<p class="size11"><span style="color: #666;display: block;margin-top: 4px;"><?php echo getRelativeTime($data_comm['date']); ?></span></p>
</div>
</div>
</li>
<? } ?>
<div class="<?php echo $data['id']; ?>"></div>
<li class="sub-userItem" style="background-color: #bebebe;margin: 0;padding: 4px;min-height: 32px;">
<div class="user-avatarCom" style="float: left;padding: 0;margin: 0;">
<img style="margin-right: 4px;" src="../img/upload/<?php echo $result['id']; ?>-mini.png" width="32" height="32" alt="" />
</div>
<form action="" method="post" onsubmit="return false;" class="form_com">
<input type="hidden" name="post_id" value="<?php echo $data['id_post']; ?>" />
<textarea name="msg_com" class="<?php echo $data['pseudo']; ?>" style="border: 1px solid #999;font-size: 11px; margin-left: 5px; height: 26px; padding: 5px; width: 343px;resize: none;font-family: Tahoma;position: relative;overflow: hidden;display: block;" id="<?php echo $data['id_post']; ?>" placeholder="Écrire un commentaire"></textarea>
</form>
<script type="text/javascript">
var J = jQuery.noConflict();
J(document).ready(function(){
J(".form_com").keypress(function(e) {
if(e.which == 13) {
var <?php echo $data['pseudo']; ?> = J('.<?php echo $data['pseudo']; ?>').val();
if( <?php echo $data['pseudo']; ?> == '') {
return false;
} else {
J('span.load-refresh').show();
setTimeout(function() {
J.ajax({
url: "ajax/add_comment.php",
type: "POST",
data: J(this).serialize(),
success: function(html) {
J('.<?php echo $data['id']; ?>').append(html);
J('.<?php echo $data['pseudo']; ?>').val('');
J('span.load-refresh').hide();
return false;
}
});
}, 1000);
return false;
}
}
});
});
</script>
<script type="text/javascript">window.addEvent('domready', function() {new DynamicTextarea('<?php echo $data['id_post']; ?>');});</script>
</li>
</ul>
</div>
</li>
<? } ?>
</ul>
</div>
Merci pour votre aide

Bonjour,
J'ai un problème avec mon système de commentaires :
Quand je post un seul commentaire (manuellement sur phpmyadmin), le résultat affiche deux mêmes commentaires postés par les deux seuls membres inscrits.
Par exemple, j'écris "Bonjour" dans le post ayant l'id "1", le résultat affichera 2 fois "Bonjour" :
- Une fois c'est moi qui l'écrit
- Une autre fois, c'est l'autre membre
Je crois qu'il y a des gros changements à faire dans mon code :
Il y a que 2 requêtes : une pour lister les news, et l'autre pour lister les commentaires liés au news.
J'ai 3 tables :
[b]wa_communaute[/b] : id AI, pseudo, pass, mail
[b]wa_comment[/b] : id_com AI, membre_id (l'id du membre qui post), msg_com, post_id (l'id du post lié au commentaire), date
[b]wa_mur[/b] : id_post AI, id_membre (l'id du membre qui post la news), poster (la new), date_heure
Comment faire pour relier tout ça, et joindre les tables, pour que chaque membre puisse commenter une new sans double commentaire ou autre erreur.
Pour la requête qui affiche les news, je sais comment faire. Je demande de l'aide pour les commentaires, j'ai du mal avec les jointures :(
[php]
<div id="mur-principal">
<ul>
<?php
$req = $connect->query('SELECT * FROM wa_mur, wa_communaute WHERE id_membre = id ORDER BY date_heure LIMIT 0,10');
$com = $connect->prepare('SELECT * FROM wa_comment JOIN wa_communaute ON membre_id = :id ORDER BY date DESC;');
while($data = $req->fetch()) { ?>
<li class="user-item" style="float: left;padding: 13px 10px 10px;width: 460px;border-top: 1px solid #cecece;word-wrap: break-word;">
<div class="user-avatar float-l" style="margin-right: 10px;">
<a href="/<?php echo htmlentities(trim($data['pseudo'])); ?>"><img src="../img/upload/<?php echo htmlentities(trim($data['id'])); ?>-mini.png" width="50" height="50" alt="" /></a>
</div>
<div class="user-title" style="margin-bottom: 5px;font-weight: bold;">
<a href="/<?php echo htmlentities(trim($data['pseudo'])); ?>" style="color: #005B83;"><?php echo htmlentities(trim($data['prenom'])); ?> <?php echo htmlentities(trim($data['nom'])); ?></a>
</div>
<div class="user-content" style="margin-left: 60px;">
<p><?php echo nl2br(trim($data['poster'])); ?></p>
</div>
<div class="sub-userContent" style="margin-left: 60px;">
<div class="sub-userFooter" style="margin-top: 6px;">
<p class="size11" style="color: #777;"><a href="" class="sub-userFooter-link" style="color: #0D5085;">J'aime</a> - <a href="" class="sub-userFooter-link" style="color: #0D5085;">Commenter</a> - <?php echo getRelativeTime($data['date_heure']); ?></p>
</div>
<ul class="sub-userData" style="list-style-type: none;">
<li>
<i class="sub-userArrow" style="background: url(../img/top-sub-user.png);background-repeat: no-repeat;height: 5px;display: block;margin-top: 5px;margin-left: 60px;"></i>
</li>
<?php $com->execute(array('id' => $data['id']));
while($data_comm = $com->fetch()){ ?>
<li class="sub-userItem" style="background-color: #bebebe;margin: 0;padding: 4px;margin: 0 0 1px;min-height: 32px;">
<div class="user-avatarCom" style="float: left;padding: 0;margin: 0;">
<img style="margin-right: 4px;" src="../img/upload/<?php echo $data_comm['membre_id']; ?>-mini.png" width="32" height="32" alt="" />
</div>
<div class="sub-userCom" style="overflow: hidden;padding-left: 4px;">
<div>
<p class="size11">
<a href="/<?php echo htmlentities(trim($data_comm['pseudo'])); ?>" style="color: #005B83;">
<b><?php echo htmlentities(trim($data_comm['prenom'])); ?> <?php echo htmlentities(trim($data_comm['nom'])); ?></b></a>
<span> <?php echo nl2br(htmlspecialchars($data_comm['msg_com'])); ?></span>
</p>
</div>
<div>
<p class="size11"><span style="color: #666;display: block;margin-top: 4px;"><?php echo getRelativeTime($data_comm['date']); ?></span></p>
</div>
</div>
</li>
<? } ?>
<div class="<?php echo $data['id']; ?>"></div>
<li class="sub-userItem" style="background-color: #bebebe;margin: 0;padding: 4px;min-height: 32px;">
<div class="user-avatarCom" style="float: left;padding: 0;margin: 0;">
<img style="margin-right: 4px;" src="../img/upload/<?php echo $result['id']; ?>-mini.png" width="32" height="32" alt="" />
</div>
<form action="" method="post" onsubmit="return false;" class="form_com">
<input type="hidden" name="post_id" value="<?php echo $data['id_post']; ?>" />
<textarea name="msg_com" class="<?php echo $data['pseudo']; ?>" style="border: 1px solid #999;font-size: 11px; margin-left: 5px; height: 26px; padding: 5px; width: 343px;resize: none;font-family: Tahoma;position: relative;overflow: hidden;display: block;" id="<?php echo $data['id_post']; ?>" placeholder="Écrire un commentaire"></textarea>
</form>
<script type="text/javascript">
var J = jQuery.noConflict();
J(document).ready(function(){
J(".form_com").keypress(function(e) {
if(e.which == 13) {
var <?php echo $data['pseudo']; ?> = J('.<?php echo $data['pseudo']; ?>').val();
if( <?php echo $data['pseudo']; ?> == '') {
return false;
} else {
J('span.load-refresh').show();
setTimeout(function() {
J.ajax({
url: "ajax/add_comment.php",
type: "POST",
data: J(this).serialize(),
success: function(html) {
J('.<?php echo $data['id']; ?>').append(html);
J('.<?php echo $data['pseudo']; ?>').val('');
J('span.load-refresh').hide();
return false;
}
});
}, 1000);
return false;
}
}
});
});
</script>
<script type="text/javascript">window.addEvent('domready', function() {new DynamicTextarea('<?php echo $data['id_post']; ?>');});</script>
</li>
</ul>
</div>
</li>
<? } ?>
</ul>
</div>
[/php]
Merci pour votre aide ;)