S A N T A Posted April 24, 2008 Share Posted April 24, 2008 Okay i am working in a blog from scratch and it is suppose to display previous blog entries and comments but it only shows the current blog entry and it says there is 1 comment but it doesn't display it.... i also get this error Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\index.php on line 47 ok here is the code <?php require("header.php"); $sql = "SELECT entries.*, categories.cat FROM entries, categories WHERE entries.cat_id = categories.id ORDER BY dateposted DESC LIMIT 1;"; ?> <div id="main"> <?php $result = mysql_query($sql)or die(mysql_error()); $row = mysql_fetch_assoc($result); echo "<h2><a href='viewentry.php?id=" . $row['id'] . "'>" . $row['subject'] . "</a></h2><br />"; echo "<i>In <a href= viewcat.php?id=" . $row['cat_id'] ."'>" . $row['cat'] . "</a> - Posted on " . date("D jS F Y g.iA", strtotime($row['dateposted'])) . "</i>"; echo "<p>"; echo nl2br($row['body']); echo "</p>"; echo "<p>"; $commsql = "SELECT name FROM comments WHERE blog_id = " . $row['id'] . " ORDER BY dateposted;"; $commresult = mysql_query($commsql); $numrows_comm = mysql_num_rows($commresult); if($numrows_comm == 0) { echo "<p>No comments.</p>"; } else { echo "(<strong>" . $numrows_comm . "</strong>) comments : "; $i = 1; while($comrow = mysql_fetch_assoc($commresult)) { echo "<a href='viewentry.php?id=" . $row['id'] ."#comment" . $i . "'>" . $commrow['name'] . "</a> "; $i++; } } ?> </div> <div id="bar"> <?php echo "</p>"; $prevsql = "SELECT entries.*, categories.cat FROM entries, categories WHERE entries.cat_id = categories.id ORDER BY dateposted DESC LIMIT 1, 5;"; $prevresult = mysql_query($presql); $numrows_prev = mysql_num_rows($prevresult); if($numrows_prev == 0) { echo "<p>No previous entries.</p>"; } else { echo "<ul>"; while($prevrow = mysql_fetch_assoc($prevresult)) { echo "<li><a href='viewentry.php?id=" . $prevrow['id'] . "'>" . $prevrow ['subject'] . "</a></li>"; } } echo "</ul>"; ?> </div> <?php require("footer.php"); ?> Help appreciated Quote Link to comment https://forums.phpfreaks.com/topic/102806-solved-comment-not-working/ Share on other sites More sharing options...
BlueSkyIS Posted April 24, 2008 Share Posted April 24, 2008 i suggest that you always die after mysql_query() in case there are errors in your SQL: $commresult = mysql_query($commsql) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/102806-solved-comment-not-working/#findComment-526602 Share on other sites More sharing options...
DeanWhitehouse Posted April 24, 2008 Share Posted April 24, 2008 this might be it $prevsql = "SELECT entries.*, categories.cat FROM entries, categories // $prevsql WHERE entries.cat_id = categories.id ORDER BY dateposted DESC LIMIT 1, 5;"; $prevresult = mysql_query($presql); //$presql $numrows_prev = mysql_num_rows($prevresult); Quote Link to comment https://forums.phpfreaks.com/topic/102806-solved-comment-not-working/#findComment-526604 Share on other sites More sharing options...
S A N T A Posted April 24, 2008 Author Share Posted April 24, 2008 both of those did absolutely nothing except the die one Quote Link to comment https://forums.phpfreaks.com/topic/102806-solved-comment-not-working/#findComment-526605 Share on other sites More sharing options...
DeanWhitehouse Posted April 24, 2008 Share Posted April 24, 2008 did you change what i said, or just copied and pasted the code? if you just copied and pasted, it won't here is the code, with changes $prevsql = "SELECT entries.*, categories.cat FROM entries, categories WHERE entries.cat_id = categories.id ORDER BY dateposted DESC LIMIT 1, 5;"; $prevresult = mysql_query($prevsql); $numrows_prev = mysql_num_rows($prevresult); Quote Link to comment https://forums.phpfreaks.com/topic/102806-solved-comment-not-working/#findComment-526607 Share on other sites More sharing options...
S A N T A Posted April 24, 2008 Author Share Posted April 24, 2008 cool now i just need it to display the comments and thanks a bunch Quote Link to comment https://forums.phpfreaks.com/topic/102806-solved-comment-not-working/#findComment-526612 Share on other sites More sharing options...
DeanWhitehouse Posted April 24, 2008 Share Posted April 24, 2008 Np, read the comments next time though, there were there for a reason Quote Link to comment https://forums.phpfreaks.com/topic/102806-solved-comment-not-working/#findComment-526614 Share on other sites More sharing options...
DeanWhitehouse Posted April 24, 2008 Share Posted April 24, 2008 if it's solved, please click solved at the bottom of the page. Quote Link to comment https://forums.phpfreaks.com/topic/102806-solved-comment-not-working/#findComment-526654 Share on other sites More sharing options...
S A N T A Posted April 25, 2008 Author Share Posted April 25, 2008 well half of its solved Quote Link to comment https://forums.phpfreaks.com/topic/102806-solved-comment-not-working/#findComment-526706 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.