Site Cloner PHP Script
Bargain Hunter PHP Script
Job Hunter PHP Script
Site Login and Access Control PHP Script

Jquery Pagination and PHP

This example uses a Jquery plugin called DataTables to paginate results from PHP or mySQL. For example, the results could be many items from an rss feed or rows from a mySQL query. The plugin can be dowloaded at http://datatables.net. This plugin makes it very easy to automatically sort ant amount of data into a clean, paginated, stylish table.

To use DataTables,
1) Download it.
2) Add the plugin script into the head of your file.
3) Add a Jquery function to initialize it:
Function:
$(document).ready(function(){
$(‘#example’).dataTable();
});
4) Make sure your <table> has id=”example” and you use <thead> and <tbody> tags. The file pagination_datatables_bare_bones.php already has done this.
5) Customize the css.
<?php
//session_start();
include('connect.inc');
$db= public_db_connect();

?>

<html>
<head>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
<script src="DataTables/media/js/jquery.dataTables.min.js" type="text/javascript"></script>
</head>
 

  <script>
  $(document).ready(function(){
    $('#example').dataTable();
});
  </script>
 <?php

####can put links too.
$link1= "{$_SERVER['PHP_SELF']}?orderby=lastname";
//$my link = '<td align="left"><a href="'.$link1.'"><b>First Name</b></a></td>';
		//echo $order_by;		
	echo '<table  class="display" id="example" align="center" cellspacing="0" cellpadding="5" bgcolor="#E0606B" width="100%">
	<thead><tr>
		<th align="left"><b>Last Name</b>'.' '.'<a href="'.$_SERVER['PHP_SELF'].'?orderby=lastname asc"><b>asc</b></a>'.' '.'<a href="'.$_SERVER['PHP_SELF'].'?orderby=lastname desc"><b>desc</b></a></th>
		<th align="left"><a href="'.$_SERVER['PHP_SELF'].'?orderby=lname"><b>First Name</b></a></th>
		<th align="left"><b>Email</b></th>
		<th align="left"><b>Age</b></th>
		<th align="left"><b>Weight</b></th>
		<th align="left"><b>Height</b></th>
		<th align="left"><b>Date</b></th>
	</thead></tr>';


$command = "select * from table_sort ORDER by date DESC"; 
$result = mysqli_query($db, $command);
 
				$command2= "SELECT DISTINCT email, firstname, lastname, age, weight, height, date FROM table_sort ORDER BY lastname asc ";
				$result2 = mysqli_query($db, $command2);
				if ($result2 && mysqli_num_rows($result2) > 0) {
		
			    echo  '<tbody>';
			   while ($row = mysqli_fetch_assoc($result2)) {
			 
								
		$bg =($bg=='#A7C6BA' ? '#f9f9f9' : '#A7C6BA');
		echo '<tr bgcolor="' . $bg . '">
			<td align="left">' .$row["lastname"]. '</td>
			<td align="left">' .$row["firstname"]. '</td>
			<td align="left">' .$row["email"]. '</td>
			<td align="left">' .$row["height"]. '</td>
			<td align="left">' .$row["age"]. '</td>			
			<td align="left">' .$row["weight"]. '</td>
			<td align="left">' .$row["date"]. '</td>
			</tr>';
			}			
			
	echo '</tbody></table>';	

}

 ?>
<div style="text-align:center;"></div>
</div>