Speed up development with full-stack environments for every branch.

Learn More

xxxred [PHP, pagination, database, MySQL and dbms]

Forked from PHP pagination example using MySql database.

45 Runs 40 Views 5 Copies

Pagination PHP Script and Tutorial for PHP MySQL Programmers Paging Results



hatim.haffane 1

published 6 months ago

if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; }; 
$start_from = ($page-1) * $num_rec_per_page; 
$sql = "SELECT * FROM student LIMIT $start_from, $num_rec_per_page"; 
$rs_result = mysql_query ($sql); //run the query
while ($row = mysql_fetch_assoc($rs_result)) { 
            <td><?php echo $row['Name']; ?></td>
            <td><?php echo $row['Phone']; ?></td>            
$sql = "SELECT * FROM student"; 
$rs_result = mysql_query($sql); //run the query
$total_records = mysql_num_rows($rs_result);  //count number of records
$total_pages = ceil($total_records / $num_rec_per_page); 

echo "<a href='pagination.php?page=1'>".'|<'."</a> "; // Goto 1st page  

for ($i=1; $i<=$total_pages; $i++) { 
            echo "<a href='pagination.php?page=".$i."'>".$i."</a> "; 
echo "<a href='pagination.php?page=$total_pages'>".'>|'."</a> "; // Goto last page
Please login/signup to get access to the terminal.

Your session has timed out.

Dismiss (the page may not function properly).