Hi all,
I have the following pagination script, when it gets to the 10th comment you should then go to the next page to display the next 10 and so on. The problem is that in my testing O have 12 results currently, and it is displaying all 12 on the page. When I click on 'Next' it simply refreshes the same page.
I know I need the issue of only displaying 10 results per page, but I also feel that I don't have the pagination working either, ie that the next 10 link may not work - happy to be told otherwise. If someone could help with the first part that would be great!Here is the script:
////Get data from users
$user_id=$_SESSION['user_id'];
$query1="SELECT oauth_uid, oauth_provider FROM users where userid='" . $user_id . "'";
$result1 = $mysqli->query($query1) or die($mysqli->error.__LINE__);
// GOING THROUGH THE DATA
if($result1->num_rows > 0) {
$row = $result1->fetch_assoc();
$oauth_uid=$row['oauth_uid'];
$oauth_provider=$row['oauth_provider'];
}
/////////////////////////////////////////////
///////////Get data from comments, the item id comes from the page, which is obtained earlier in the script
$query="SELECT name, comment, anonymous, userid, item_id, comment_date from comments where item_id='$item_id'";
$result2 = $mysqli->query($query) or die($mysqli->error.__LINE__);
// GOING THROUGH THE DATA
if($result2->num_rows > 0) {
$limit=10;
if (empty($s)) {
$s=0;
}
// get results
$query1 .= " limit $s,$limit";
// begin to show results set
echo "<br></br>";
echo "<h3>Comments for this article:</h3>";
$count = 1 + $s ;
// now you can display the results returned
while ($row= mysqli_fetch_array ($result2)) {
$anonymous=$row['anonymous'];
$name=$row['name'];
// echo "<p>anonymous=$anonymous</p>";
$comment = $row['comment'];
$oauth_provider=$row['oauth_provider'];
//Get the number of roes from the query:
$numrows = $result2->num_rows;
if (($anonymous==true)&& ($oauth_provider="facebook")){
echo "<p>$count.) ".$comment."<br/><sub><b>Comment by: </b>'Anonymous Poster'</sub><hr /><p>";
}
else{
echo "<p>$count.) ".$comment."<br/><sub><b>Comment by: </b>".$name."</sub><hr /><p>";
}
$count++ ;
}
$currPage = (($s/$limit) + 1);
//break before paging
echo "<br />";
// next we need to do the links to other results
if ($s>=1) { // bypass PREV link if s is 0
$prevs=($s-$limit);
print " <a href='$PHP_SELF?s=$prevs'><<> Prev 10</a>  ";
Prev 10</a>  ";
}
// calculate number of pages needing links
$pages=intval($numrows/$limit);
// $pages now contains int of pages needed unless there is a remainder from division
if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}
// check to see if last page
if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {
// not last page so give NEXT link
$news=$s+$limit;
echo " <a href='$PHP_SELF?s=$news'>Next 10 >></a>";
}
$a = $s + ($limit) ;
if ($a > $numrows) { $a = $numrows ; }
$b = $s + 1 ;
echo "<p>Showing results $b to $a of $numrows</p>";
}
Thanks,
G