kjtocool Posted December 18, 2007 Author Share Posted December 18, 2007 Maybe I was too quick to deem this a success, I tried to implement it into my code, and the result set is returning every matching comment, not what I requested in the limit. The issue is not with the query, because when I run it in phpmyadmin, it returns only 10 rows. Here is my code: <?php // As of right now, there is no commentStart in the URL $comment_start = $_GET['commentStart']; if ($comment_start == "") { $comment_start = 0; } $query = "SELECT (SELECT COUNT(*) FROM Article_Comments WHERE article_ID = $article_ID) AS total_count, user_ID, comment FROM Article_Comments WHERE article_ID = $article_ID ORDER BY comment_ID LIMIT $comment_start, 10"; $result = mysqli_query($databaseConnect, $query); $row = mysqli_fetch_assoc($result); $num_comments = $row['total_count']; if ($num_comments == 0) { echo '<p class="style13">Comments <span class="style10">(There are no comments to show.) </span></p>'; } else { $comments_shown = $num_comments; if ($comments_shown > 10) { $comments_shown = 10; } echo '<p class="style13">Comments <span class="style10">(Showing 1 - ' . $comments_shown . ' of ' . $num_comments . ' comments) </span></p>'; } while ($row) { $user_id = $row['user_ID']; $comment = $row['comment']; $databaseConnect2 = mysqli_connect("localhost", "user", "pass", "db") Or die("Unable to connect to the database."); $query2 = "SELECT username FROM phpbb_users WHERE user_id = $user_id"; $result2 = mysqli_query($databaseConnect2, $query2); $row2 = mysqli_fetch_assoc($result2); $user_name = $row2['username']; echo '<table width="70%" border="0" align="center" cellpadding="0" cellspacing="1">'; echo '<tr>'; echo '<td bgcolor="#FBFBFB"><span class="style14">' . $user_name . ' says ...</span></td>'; echo '</tr>'; echo '<tr>'; echo '<td bgcolor="#FBFBFB" class="style12">' . $comment . '</td>'; echo '</tr>'; echo '</table><br />'; mysqli_free_result($result2); mysqli_close($databaseConnect2); $row = mysqli_fetch_assoc($result); } mysqli_free_result($result); ?> I don't understand how the while ($row) comment can possibly be returning all 12 comments, when this query: SELECT ( SELECT COUNT( * ) FROM Article_Comments WHERE article_ID =31165 ) AS total_count, user_ID, COMMENT FROM Article_Comments WHERE article_ID =31165 ORDER BY comment_ID LIMIT 0 , 10 Returns only 10 rows. Link to comment https://forums.phpfreaks.com/topic/82213-solved-how-do-you-get-the-result-of-a-count/page/2/#findComment-417978 Share on other sites More sharing options...
emehrkay Posted December 18, 2007 Share Posted December 18, 2007 seems strange. try this and remove the feth_array from everywhere else while($row = mysqli_fetch_assoc($result)){ ... } Link to comment https://forums.phpfreaks.com/topic/82213-solved-how-do-you-get-the-result-of-a-count/page/2/#findComment-417988 Share on other sites More sharing options...
kjtocool Posted December 18, 2007 Author Share Posted December 18, 2007 That worked (though I left in the initial fetch, so it displayed starting at 1). Of course, I then went back, and uploaded the code I posted above, and of course, it worked fine this time. Just that kind of day. Thanks again for your help. Link to comment https://forums.phpfreaks.com/topic/82213-solved-how-do-you-get-the-result-of-a-count/page/2/#findComment-418003 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.