Pagination with PHP, jQuery and MySQL.

So many emails hit my inbox with readers asking me how to implement pagination with php. So i decided to put one together using Jquery, php and Mysql. It looks difficult, but its rather simple.

The Structure contains three PHP files and two js files includes jQuery plugin.

-database.php (Database Configuration)
-pagination.php
-paginationdata.php

Database Table

CREATE TABLE users
(
users_id INT PRIMARY KEY AUTO_INCREMENT,
user TEXT
);

config.php
You have to change hostname, username, password and databasename.

<!--?php $mysql_hostname = "localhost"; $mysql_user = "username"; $mysql_password = "password"; $mysql_database = "database"; $bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Opps some thing went wrong"); mysql_select_db($mysql_database, $bd) or die("Opps some thing went wrong"); ?-->


pagination.php

User interface page.

<!--?php include('config.php'); $per_page = 9; //Calculating no of pages $sql = "select * from users"; $result = mysql_query($sql); $count = mysql_num_rows($result); $pages = ceil($count/$per_page) ?-->
<ul id="pagination"> <!--?php<br /--> //Pagination Numbers
for($i=1; $i&lt;=$pages; $i++)
{
echo '
    <li id="'.$i.'">'.$i.'</li>
';
}
?&gt;</ul>

paginationdata.php
Simple php script display data from the users table.

<!--?php include('config.php'); $per_page = 9; if($_GET) { $page=$_GET['page']; } $start = ($page-1)*$per_page; $sql = "select * from users order by user_id limit $start,$per_page"; $result = mysql_query($sql); ?-->

Demo To Follow Shortly! & Download

admin No comments
Leave a comment

Tensor is a sleek template that can fit many different websites. It can have a…

Levante is a simple, clean, minimalist and modern template suitable for business and corporate sites….

3 Column layout Joomla 1.5 template. This Joomla template has lots of parameters. Easy to…

Scorpii is a modern and professional Joomla 1.5 template suitable for business and corporate sites….

Azimuth is a clean template best suited for business and corporate websites. It has subtle…