Bonjour à tous ,
J'ai une page commentaire assez complète pour ce dont j'ai besoin et mon dernier ajout concerne la pagination des commentaires limiter a 10 par page.
J'ai mis en place le codage mais maintenant je ne vois plus les commentaires, si quelqu'un pouvais me dire ou est l'erreur.
Merçi d avance .
PS: j'essaye de me mettre au norme donc si vous voyez un prb
.
CODAGE:
<?php
include("functions/db_connect.php");
include("functions/tables.php");
$sql_news_query = "SELECT n.news_ID AS n_id,
n.flag AS n_flag,
n.title AS n_title,
n.postdate AS n_date,
n.posttime AS n_time,
n.body AS n_body,
n.link1 AS n_link1,
n.username AS n_username,
cat.categorie_ID AS c_id,
cat.name AS c_name,
cat.logo AS c_logo
FROM $tblNews n
INNER JOIN $tblNewsCategories cat
ON cat.categorie_ID = n.categorie_ID
WHERE n.news_ID ='" . (int)$_GET['nid'] . "'";
$sql_users_query = "SELECT * FROM $tblUsers ";
$news_result = mysql_query($sql_news_query) or die(mysql_error());
while($row_news = mysql_fetch_object($news_result)) {
?>
<table cellspacing="0" width="100%" cellpadding="0">
<tr>
<td width="100%" colspan="2" valign="middle" class="titre" height="40">
<p> <img src="images/flags/<?=$row_news->n_flag?>"> <b><?=$row_news->n_title?></b></p>
</td>
</tr>
<tr>
<td width="970" colspan="2"class="plus">
<p> Par <b><a href="?section=compte/user_profile&uid=<?=$row_news->m.member_ID?>"><?=$row_news->n_username?></a></b> Posté le: <?=$row_news->n_date?> - <?=$row_news->n_time?></p>
</td>
</tr>
<tr>
<td width="155" valign="top"><img src="images/news/<?=$row_news->c_logo?>" width="150" height="80" alt="<?=$row_news->c_name?>" align="top"></td>
<td width="811"class="include"valign="top"> <?=ubb(nl2br($row_news->n_body))?></td>
</tr>
<tr>
<td width="155">
<?php
if($row_news->n_link1 == "" || $row_news->n_link1 == "http://") {
echo "";
} else {
echo "<tr>";
echo "<td height=\"15\" colspan=\"2\"class=\"plus\"> Source:<br/>
<a href='" . $row_news->n_link1 . "' target=\"_blank\"><font class=\"plus\">" . $row_news->n_link1 ."</font></a>";
}
echo "</tr>";
echo "</table>";
}
if(isset($_POST['post_comment'])) {
$insert_sql = "INSERT INTO $tblNewsComments (news_ID, postdate, posttime, body, username) VALUES (
'" . $_GET['nid'] . "',
'" . $_POST['postdate'] . "',
'" . $_POST['posttime'] . "',
'" . $_POST['body'] . "',
'" . $_POST['username'] . "')";
$insert_query = mysql_query($insert_sql) or die(mysql_error());
include("news_comments_redirect.php");
} else {
$limit_par_comments = 10;
if(isset($_GET['nid']))
{
$nid = $_GET['nid'];
$nid = $nid - 1;
}
else
{
$nid = 0;
}
$from = $nid * $limit_par_comments;
$sql_comments_query = "SELECT c.news_ID AS c_news_id,
c.comment_ID AS c_comment_id,
c.postdate AS c_date,
c.posttime AS c_time,
c.body AS c_body,
c.username AS c_username
FROM $tblNewsComments c
WHERE c.news_ID ='" . (int)$_GET['nid'] . "'
ORDER BY c.comment_ID
LIMIT $from,$limit_par_comments ";
$sql_users_query = "SELECT * FROM $tblUsers m ";
$comments_result = mysql_query($sql_comments_query) or die(mysql_error());
echo "<br/>";
echo "<b> Commentaires:</b><br/>";
if(mysql_num_rows($comments_result) == "0") {
echo "Pas de commentaires...<br><br/>";
} else {
$a = 1;
while($row_comment = mysql_fetch_object($comments_result)) {
?>
<table width="100%" border="0" cellpadding="5" cellspacing="0" class="include">
<tr>
<td width="60%"> #<?php echo $a;?>
| <b><a href="?section=compte/user_profile&uid=<?=$row_comment->m.member_ID?>"><?=$row_comment->c_username?></a></b> le <?=$row_comment->c_date?> - <?=$row_comment->c_time?></td>
</tr>
<tr>
<td colspan="2"> <?=ubb(nl2br(htmlentities($row_comment->c_body)))?></td>
</tr>
</table>
<br/>
<?$row_comment = ceil($nb_msg / $limit_par_comments);
for($nid=1;$nid<=$nb_pages;$nid++)
{
?><a href="?section=news_comments&page=<? echo $nid; ?>"><? echo $nid; ?></a>
<?php
$a ++;
}
}
if(isset($_SESSION['login']) == "1") {
?>
<form action="" method="post" name="commentform">
<table width="100%" border="0" cellpadding="5" cellspacing="0" >
<tr>
<td width="150"></td>
<td>
<a onclick="document.commentform.body.value+=':)'"><img src="images/smileys/smile.gif" border="0" width="22" height="22"></a>
<a onclick="document.commentform.body.value+=':D'"><img src="images/smileys/biggrin.gif" border="0" width="22" height="22"></a>
<a onclick="document.commentform.body.value+=':cool:'"><img src="images/smileys/cool.gif" border="0" width="22" height="25"></a>
<a onclick="document.commentform.body.value+=':cry:'"><img src="images/smileys/cry.gif" border="0" width="22" height="22"></a>
<a onclick="document.commentform.body.value+=':lol:'"><img src="images/smileys/laugh.gif" border="0" width="22" height="22"></a>
<a onclick="document.commentform.body.value+=':rolleyes:'"><img src="images/smileys/rolleyes.gif" border="0" width="22" height="22"></a>
<a onclick="document.commentform.body.value+=':P'"><img src="images/smileys/tongue.gif" border="0" width="22" height="22"></a>
<a onclick="document.commentform.body.value+=';)'"><img src="images/smileys/wink.gif" border="0" width="22" height="22"></a>
<br>
<input type="button" onclick="document.commentform.body.value+='[b]TEXT[/b]'" value="B">
<input type="button" onclick="document.commentform.body.value+='[i]TEXT[/i]'" value="I">
<input type="button" onclick="document.commentform.body.value+='[u]TEXT[/u]'" value="U">
<input type="button" onclick="document.commentform.body.value+='[s]TEXT[/s]'" value="S">
<input type="button" onclick="document.commentform.body.value+='[quote]TEXT[/quote]'" value="Quote">
<input type="button" onclick="document.commentform.body.value+='[img]URL[/img]'" value="IMG">
<input type="button" onclick="document.commentform.body.value+='[url]URL[/url]'" value="URL">
<input type="button" onclick="document.commentform.body.value+='[email]E-MAIL[/email]'" value="E-Mail">
</td>
</tr>
<tr>
<td width="150" valign="top"class="include">BBCode est ON<br/>HTML est OFF</td>
<td><textarea name="body" cols="30" rows="5" class="include"></textarea></td>
</tr>
<tr>
<td><input type="hidden" name="postdate" value="<?=date("d/m/Y")?>" >
<input type="hidden" name="posttime" value="<?=date("H:i")?>" >
<input type="hidden" name="username" value="<?=$_SESSION['nickname']?>" >
</td>
</tr>
<tr>
<td width="150"></td>
<td><input type="submit" name="post_comment" value="Poster Commentaire">
</td>
</tr>
</table>
</form>
<?php
}
else
{
echo "Vous devez être logué pour poster un commentaire!";
}
}
?>