Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Tony David  >  Page Creator  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: example script of the class with a mysql database
Class: Page Creator
Generates navigation links between listing pages
Author: By
Last change: changed mysql password and mysql databasename for my own security reasons :)
Date: 2004-04-23 15:45
Size: 1,360 bytes
 

Contents

Class file image Download
<?
require_once "pagecreator.php";
$db_HOST="localhost";
$db_USER="root";
$db_PASS="PASSWORD";
$db_NAME="MYSQLDATABASE"//NAME OF THE DATABASE WHERE THE EXAMPLE TABLE CAN BE FOUND

$dbh=mysql_connect ($db_HOST,$db_USER,$db_PASS
        or die (
'I cannot connect to the database because: ' mysql_error());
mysql_select_db ($db_NAME,$dbh);


// Make query
if (!$st$st=0
$st=(int) $st;

if (!
$rows$rows=10
$rows=(int) $rows;
if (
$rows<1$rows=10;
$query_db="select * from categories order by cat_id limit $st,$rows";
$query_total_cats="select * from categories ";

$result=mysql_query($query_db);
$total_cats=mysql_num_rows(mysql_query($query_total_cats));

//make pagelinks with pagecreatorclass
$pg=new page_creator();
$pg->TotalItems=$total_cats;
$pg->ItemsPerPage=$rows;

$pg->PrevNext=true;
$pg->FirstLast=true;
$pg->TrailingPages=2;
$pg->ShowTotalPages=true;
$pg->ShowTotalPagesString="Total of pages: ";

$pg->ScriptVariable="st";
$pg->Parameters=array('amount'=>$rows);

$nav=$pg->Create_Pagelinks();
print 
$nav."<br />";

// display the contents of the page
print '<table width="60%" border="1px">';
while (
$r=mysql_fetch_array($result)) {
    print 
'<tr><td>' $r['cat_id'] . '</td>';
    print 
'<td>' $r['cat_1'] . '</td>';
    print 
'<td>' $r['cat_2'] . '</td></tr>';
    }
print 
'</table>';

//
?>