My VIDEO courses:

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

  1. Video tutorial: How to create PHP Shopping cart using SESSION object variables
  2. Video PHP tutorials: Manage statistics ( stats ) using the SERVER object
  3. Video tutorials: PHP Mail function – How to send emails from your web server or localhost
  4. Video tutorial: How to integrate, integrating paypal buy now button with php and your database
  5. Video Tutorials – How to create website menus using free css menu builder
1 Star2 Stars3 Stars4 Stars5 Stars (6 votes, average: 4.83 out of 5)
Loading ... Loading ...

Comments (1)

rogrt March 4th, 2010 at 14:38    

I love this vid.

Leave a reply

Name *

Mail *

Website

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word