PHP video tutorials: Pagination display results from database tables divided to multiple pages – paging
If you have long tables it is not practical to display all the results in one page.
There is a need to divide the results into smaller groups and display them on different pages.
Pagination technique is commonly used by webmasters.
I will explain you this important technique in this post.
I think that you shouldn’t remember everything by hard you can just use my technique in your projects, it works great!
Here is the code I used in this lesson:
<?php
$db = mysql_connect(“localhost”,”alex”,”alex”);
mysql_select_db(“page”,$db);
if (isset($_GET['page']))
{
$page=$_GET['page'];
$page=mysql_real_escape_string($page);
}
else
$page = 1;
?>
This is our table:
<?php
$result = mysql_query(“SELECT * from my_table”,$db);
$rows = mysql_num_rows($result);
$per_page = 5;
$total_pages = ceil($rows/$per_page);
echo “You are on page $page of $total_pages<br>”;
if ($page != 1)
{
echo ” <a href=’page.php?page=1′>
Related Posts
- Video tutorial: How to create PHP Shopping cart using SESSION object variables
- Video PHP tutorials: Manage statistics ( stats ) using the SERVER object
- Video tutorials: PHP Mail function – How to send emails from your web server or localhost
- Video tutorial: How to integrate, integrating paypal buy now button with php and your database
- Video Tutorials – How to create website menus using free css menu builder
Filed Under: PHP and MySql
Tags: divide, how, page, pagination, paging, php, to, tutorial







(6 votes, average: 4.83 out of 5)
Comments (1)
I love this vid.
Leave a reply