PHP Classes

File: example1.php

Recommend this page to a friend!
  Classes of Usman Didi Khamdani   Easy Paging Class   example1.php   Download  
File: example1.php
Role: Example script
Content type: text/plain
Description: this example is used to obtain a number of data with display limitation into the pages, without $_GET variable plus CSS Rules
Class: Easy Paging Class
Show navigation links for listings split in pages
Author: By
Last change:
Date: 12 years ago
Size: 3,348 bytes
 

Contents

Class file image Download
<?php

/*
this example is used to obtain a number of data with display limitation into the pages, without $_GET variable plus CSS Rules
author: usman didi khamdani
author's email: usmankhamdani@gmail.com
author's phone: +6287883919293
*/

?>
<!doctype html>
<html lang="en">
<head>
<title>Paging Class :: Page without $_GET variable plus CSS Rules</title>
<style type="text/css">
body { font: 80% sans-serif,Verdana; color:#111 }
a { color:#f00;text-decoration:none; }
a:hover { color:#00f; }
#display_content h3 { text-align: center }
#content { border: 1px solid #111; margin-left:auto;margin-right:auto; width:80% }
#content th { background: #111; color:#fff; padding: 5px 10px }
#content td { border: 1px solid #111; text-align: left; padding: 5px 10px }
.first_offline, .prev_offline, .next_offline, .last_offline { display:none; }
.page_online { color:#000; }
.page_offline { color:#00f; font-size: 120%; font-weight:bold; text-decoration:underline; }
.page_thumbnail { text-align:center; padding: 10px }
</style>
</head>
<body>
<h3>Page without $_GET variable plus CSS Rules</h3>
<?php

// define first, prev, next and last thumbnail
define("_FIRST","First");
define("_PREV","Prev");
define("_NEXT","Next");
define("_LAST","Last");

include(
"paging.class.php");

$host = "localhost"; // database host name
$user = "root"; // database user name
$password = ""; // database user password
$db = "test"; // database name

$host_conn = mysql_connect($host,$user,$password); // connect to host
if(!$host_conn) {
    die(
mysql_error());
}
$db_conn = mysql_select_db($db, $host_conn); // connect to database
if(!$db_conn) {
    die(
mysql_error());
}

// current page
if(isset($_GET['page']) && $_GET['page']!="") {
   
$page = $_GET['page'];
} else {
   
$page = 1;
}

$query1 = "SELECT no FROM book WHERE category = 'PHP'";
$check = mysql_query($query1);

if(!
$check) {
    die(
mysql_error());
}

$sum_data = mysql_num_rows($check); // sum of data
   
$max_row = 5; // maximum number of rows of data to be displayed in a page
$num = 3; // number of page thumbnails

$d = new Paging($page,$max_row,$sum_data);

// get limit;
$query2 = "SELECT * FROM book WHERE Category = 'PHP' ORDER BY Published_Year DESC,Title ASC ".$d->limit();
// create thumbnail;
$thumbnail = $d->thumbnail($num);

echo
"<div id=\"display_content\"><p>current page = $page<br />number of page = ".ceil($sum_data/$max_row)."<br />maximum number of rows of data to be displayed in a page = $max_row<br />sum of data = $sum_data<br />number of page thumbnails = $num</p><p>mysql_query = <strong>$query2</strong></p>";

$display = mysql_query($query2);

if(!
$display) {
    die(
mysql_error());
}

echo
"<hr /><h3>List of PHP Books</h3><table id=\"content\"><tr><th>No.</th><th>Title</th><th>Author</th><th>Published Year</th></tr>";
$no = 0;
while(
$data = mysql_fetch_array($display)) {
   
$no++;
   
$n = (($page-1)*$max_row)+$no;
    echo
"<tr><td style=\"text-align:right\">$n.</td><td>".$data['Title']."</td><td>".$data['Author']."</td><td>".$data['Published_Year']."</td></tr>";
}

echo
"</table></div>$thumbnail";

?>
<hr />
<p><a href="example2.php">Example 2: Page with $_GET variable(s)</a><br />
<a href="example3.php">Example 3: Page with jQuery .load() plus CSS Rules</a></p>
</body>
<html>