You need to read the first part of this tutorial first, read here. For this tutorial I’m using FTPZilla as my FTP client to connect to my hosting service and Notepad++ as the default editor.
Here is the usage of the class,
<?php
/* -----------------------------------------------------
* File name : lhistory.php
* Version : 2
* Created by : [email protected]
* Created on : 02.06.2008
* Implemented : 16.06.2008
* Last Update : 18.04.2011
* -----------------------------------------------------
* Licensed : Non commercial, GPL, derivative codes
* from Magnolia framework. find out more on http://www.halilintar.org
* -----------------------------------------------------
* Purpose : Implemetation of paging class
* -----------------------------------------------------
*/
/*
* Call the paging class
*
*/
require_once LIB_PATH.'paging.lib.php';
/*
* Query for data that we will page, make sure not to close the query on the end.
*
*/
$query ="SELECT lh.id, CONCAT(u.fname,' ',u.lname) AS fullname, lh.ip_addr, lh.time, CONCAT(lc.notes,' ',lh.notes) AS notes
FROM log_history lh
LEFT JOIN user u ON (u.id = lh.user_id_fk)
LEFT JOIN log_code lc ON (lc.id = lh.code_id_fk)
WHERE lh.del = '0'
ORDER BY lh.time DESC ";
/*
* Initialize class
*
*/
$pagingResult = new Pagination();
/*
* Set the query
*
*/
$pagingResult->setPageQuery($query);
/*
* Make it run
*
*/
$pagingResult->paginate();
/*
* Set this variable, so if u redirect back your page you will go to the same page on the same row per page
*
*/
$this_page = $_SERVER['PHP_SELF']."?".$pagingResult->getPageQString();
/*
* Generate upper menu
*
*/
echo $pagingResult->pagingMenu();
?>
/*
* Create our table header
*
*/
<div style='border: 1px solid #CECECE; padding: 2px; margin-top: 5px; margin-bottom: 5px;'>
<table border="0" cellpadding="1" cellspacing="1" width="100%">
<tr class="listview" align="left" valign="middle">
<td width="25" align="left"> <b>NO</b> </td>
<td width="*"> <b>NAME</b> </td>
<td width="*"> <b>IP ADDRESS</b> </td>
<td width="*"> <b>TIME</b> </td>
<td width="*"> <b>REMARKS</b> </td></tr>
<?php
/*
* Checking whether there's a result from generating data on queries.
* If yes, goes to the next process
*/
if ($pagingResult->getPageRows()>= 1) {
/*
* Set the count on data
*
*/
$count = $pagingResult->getPageOffset() + 1;
/*
* Set the generated data into array
*
*/
$result = $pagingResult->getPageArray();
/*
* Do the loop on array
*
*/
while ($log_list_array = mysql_fetch_array($result, MYSQL_ASSOC)) {
$row_color = ($count % 2)?"odd":"even";?>
/*
* Generate rows of data
*
*/
<tr class="<?=$row_color?>" align="left" valign="top">
<td width="25" align="left"> <?=$count?>.</td>
<td> <?=($log_list_array["fullname"])?ucwords($log_list_array["fullname"]):"-"?> </td>
<td> <?=($log_list_array["ip_addr"])?ucwords($log_list_array["ip_addr"]):"-"?> </td>
<td> <?=($log_list_array["time"])?cplday('d M Y H:i:s',$log_list_array["time"]):"-"?> </td>
<td> <?=($log_list_array["notes"])?strtoupper($log_list_array["notes"]):"-"?> </td>
</tr>
<?php $count++;
}
} else {?>
<tr><td colspan="5" align="center" bgcolor="#e5e5e5"><br />No Data Entries<br /><br /></td></tr>
<?php } ?>
</table>
/*
* Generate below menu
*
*/
<?php echo $pagingResult->pagingMenu(); ?>
Pagination, PHP code share 😉 – Part 2 by M. Aryo N. Pratama is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
Based on a work at www.halilintar.org.
Permissions beyond the scope of this license may be available at http://www.halilintar.org/.