DeanWhitehouse Posted November 13, 2008 Share Posted November 13, 2008 I don't post here often now, but this one really has got me stuck. This is my site, and i have added a comment system. http://djw-webdesign.awardspace.com/comment.php?id=1 The count is not wrong there are 2 comments, but only one is shown, and when there was only one comment it didn't show it. This is the comment.php code, i removed the add comment code to make it shorter to read. <?php ob_start(); include 'Includes/header.php'; include 'Includes/nav.php'; ?> </div> <div id="wrapper"> <div id="page"> <div id="content"> <?php if(isset($_GET['id']) && is_numeric($_GET['id'])) { $id = $_GET['id']; $id = stripslashes($id); $sql = "SELECT * FROM djw_comments WHERE parent_id = ".$id." ORDER BY time DESC"; $sql = mysql_query($sql); $nums = mysql_num_rows($sql); $r = mysql_fetch_assoc($sql); $sql1 = mysql_query("SELECT * FROM djw_blog WHERE id =".$id); $rows = mysql_fetch_assoc($sql1); if(!$sql || !$sql1 || $id <= 0 || mysql_num_rows($sql1) == 0) { header("Location:http://djw-webdesign.awardspace.com/index.php"); exit(); } ?> <div class="post"> <h1 class="title"><a href="http://djw-webdesign.awardspace.com/blog.php#blog_id_<?php echo $rows['id']; ?>"><?php echo $rows['title'];?></a></h1> <p class="byline"><small>Posted on <?php echo date("F jS, Y",strtotime($rows['time'])); ?> by <a href="about.php?what=me"><?php echo $rows['poster']; ?></a></small></p> <div class="entry"> <p><?php echo nl2br($rows['content']); ?></p> </div> </div> <div class="post"> <h1 class="title">Comments(<?php echo $nums;?>)</h1><p class="byline"><small><a href="#comment">Comment</a></small></p> <?php while($row = mysql_fetch_assoc($sql)) { ?> <div class="entry"> <h3><a name="id<?php echo $row['id']; ?>"></a>Posted on <?php echo date("F jS, Y",strtotime($row['time'])); ?> by <a href="Javascript:void();"><?php echo wordwrap($row['poster'],40,"<br>",true); ?></a></h3> <?php $cont = $row['content']; $cont = wordwrap($cont,65,"<br>",true); $cont = nl2br($cont); $cont = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $cont); $cont = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $cont); ?> <p><?php echo $cont; ?></p> </div> <?php } ?> </div> <?php } else { header("Location:http://djw-webdesign.awardspace.com/index.php"); exit(); } ?> </div> <?php include 'Includes/sidebar.php'; include 'Includes/footer.php'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/132613-solved-only-one-comment-showing/ Share on other sites More sharing options...
revraz Posted November 13, 2008 Share Posted November 13, 2008 Do you really want to re-use $sql here? $sql = "SELECT * FROM djw_comments WHERE parent_id = ".$id." ORDER BY time DESC"; $sql = mysql_query($sql); Quote Link to comment https://forums.phpfreaks.com/topic/132613-solved-only-one-comment-showing/#findComment-689562 Share on other sites More sharing options...
DeanWhitehouse Posted November 13, 2008 Author Share Posted November 13, 2008 That shouldn't affect it though should it Quote Link to comment https://forums.phpfreaks.com/topic/132613-solved-only-one-comment-showing/#findComment-689565 Share on other sites More sharing options...
.josh Posted November 13, 2008 Share Posted November 13, 2008 That's because earlier you do this: $r = mysql_fetch_assoc($sql); Quote Link to comment https://forums.phpfreaks.com/topic/132613-solved-only-one-comment-showing/#findComment-689567 Share on other sites More sharing options...
DeanWhitehouse Posted November 13, 2008 Author Share Posted November 13, 2008 Ahh, thank you, its good to get someone to read over your code. I didn't notice that. Quote Link to comment https://forums.phpfreaks.com/topic/132613-solved-only-one-comment-showing/#findComment-689572 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.