Click here to Skip to main content
15,905,028 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi everyone, have the coding below to get the next and previous records. However, still unable to get the next record as it shows the next record picid=14, where actually the next record supposed to be picid=40.The current record is picid=4. Please advise. Thanks.
error_reporting(E_ALL ^ E_NOTICE);
mysql_connect("localhost","user","");
mysql_select_db("pq");
$_SESSION['userid'];
$_SESSION['username'];
$_SESSION['usersecurity'];
//check if the starting row variable was passed in the URL or not
if (!isset($_GET['picid']) or !is_numeric($_GET['picid'])) {
//we give the value of the starting row to 0 because nothing was found in URL
$_SESSION['year'];
$_SESSION['kra'];
$_SESSION['kpi'];
$_SESSION['measure'];
$_SESSION['target'];
$picid = 0;
//otherwise we take the value from the URL
} else {
$picid = (int)$_GET['picid'];
}
//this part goes after the checking of the $_GET var
$fetch = mysql_query("SELECT * FROM general,progress LIMIT $picid, 10")or
die(mysql_error());
//now this is the link..
echo 'Next';
$prev = $picid - 10;
//only print a "Previous" link if a "Next" was clicked
if ($prev >= 0)
echo 'Previous';
?>
Posted
Comments
W Balboos, GHB 18-Dec-15 10:49am    
You need to show what you do with $fetch .

Also, without an order by in your query you cannot be sure what record comes next.

<br>
codetrode 18-Dec-15 11:35am    
i can send you a better detailed pagination class if you want

Hi, thanks for your reply. The $fetch suppose to display the next record. Appreciate if you could send a better detail pagination. Thanks a lot.
 
Share this answer
 
PHP
             if ($replies_count !== 0) {
// find out how many rows are in the table 
$sql = "SELECT COUNT(*) FROM `phpc_topic_replies` WHERE `phpc_topic_serial`=$topic_serial";                     
$result = mysqli_query($coni,$sql) or trigger_error("SQL", E_USER_ERROR);
$r = mysqli_fetch_row($result);
$numrows = $r[0];
// number of rows to show per page
$rowsperpage = 15;
// find out total pages
$totalpages = ceil($numrows / $rowsperpage);

// get the current page or set a default
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
   // cast var as int
   $currentpage = (int) $_GET['currentpage'];
} else {
   // default page num
   $currentpage = 1;
} // end if

// if current page is greater than total pages...
if ($currentpage > $totalpages) {
   // set current page to last page
   $currentpage = $totalpages;
} // end if
// if current page is less than first page...
if ($currentpage < 1) {
   // set current page to first page
   $currentpage = 2;
} // end if

// the offset of the list, based on current page 
$offset = ($currentpage - 1) * $rowsperpage;

// get the info from the db 
$get_replies = "SELECT * FROM `phpc_topic_replies` WHERE `phpc_topic_serial`=$topic_serial AND `phpc_reply_valid`='yes' order by phpc_reply_serial asc LIMIT $offset, $rowsperpage ";                   
//$sql = "SELECT location, caption FROM photos order by id desc LIMIT $offset, $rowsperpage";
$result = mysqli_query($coni,$get_replies);
// while there are rows to be fetched...
while ($rep = mysqli_fetch_assoc($result)) {
$reply_serial = $rep['phpc_reply_serial'];
?>


HTML
<div>
<h4>echo whatevr is gonna be paginted here like this "?php echo new ??</h4>

</div>




PHP
 <?php
             
                                        }


$range = 2;
    echo '<div class="row"> <h3 class="center"> Read more replies </h3> <ul style="text-align: center;" class="pagination">';
if ($currentpage > 1) {

   echo "<li> <a href='$main_url/read/$topic_url/1'>First Page</a></li> ";

   $prevpage = $currentpage - 1;

   echo "<li> <a href='$main_url/read/$topic_url/$prevpage'><</a> </li>";
}
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
  if (($x > 0) && ($x <= $totalpages)) {
     if ($x == $currentpage) {
        echo "<li> <a href='#' class='active'>$x</a>";
  } else {
        echo "<li> <a href='$main_url/read/$topic_url/$x'>$x</a> </li> ";
      } // end else
   } // end if 
} // end for
                 
// if not on last page, show forward and last page links        
if ($currentpage != $totalpages) {
   // get next page
   $nextpage = $currentpage + 1;
    // echo forward link for next page 
   echo "<li> <a href='$main_url/read/$topic_url/$nextpage'>></a></li> ";
   // echo forward link for lastpage
   echo "<li> <a href='$main_url/read/$topic_url/$totalpages'>Last Page</a></li> ";
  
} // end if
             }
              echo '</ul></div>';
?>   

preview:
http://i.imgur.com/xHEcoFp.jpg[^]
 
Share this answer
 
v2
Comments
codetrode 19-Dec-15 2:10am    
NOTE all these is a single file the one at the tops is the getting the info from dp and middle the info you want to paginate might ba a div
and the last block are the pagination links.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900