PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of tomekglinski   Tomeks Pagination   index.php   Download  
File: index.php
Role: Example script
Content type: text/plain
Description: demo script
Class: Tomeks Pagination
Output pagination links using session to pass data
Author: By
Last change:
Date: 18 years ago
Size: 3,279 bytes
 

Contents

Class file image Download
<?php
session_start
();
include(
'pagination_class.php');
mysql_connect('localhost', 'user', 'pass');
mysql_select_db('base');
$_SESSION = array();


// **************************** EXAMPLE "let it only work" *********
echo "That how it looks by default. Not nice, but enough for ie debugging.<br><br>";
// start

$pag1 = new pagination("przyklad1"); // new object
$pag1 = $pag1->load(); //load from session if possible. Don't use it, if you want to reload data from database
$pag1->sql_query = "select * from example"; // useful:] if not in session

echo $pag1->links(); // schow links
echo "<table>"; // create and show table with data
$pag1->content();
echo
"</table>";
$pag1->save(); // write into session

// thats all:)



echo "<br><hr><br>";
//***************************** EXAMPLE "changing appearance (a little) ************
echo "A little changed view. Use CSS and it will look like a christmas tree:). Displayed 3 rows per page and 3 links to the pages.<br><br>";
// start


$pag2 = new pagination("przyklad2"); // as previously (AP)
$pag2 = $pag2->load(); // AP

$pag2->settings(3, 3);

$pag2->sql_query = "select * from example"; // AP
// change some links templates
$pag2->link_begin = ' <a href="?'.$pag2->pag_id.'=@num@"><small><b>first page</b></small></a> ';
$pag2->link_end = ' <a href="?'.$pag2->pag_id.'=@num@"><small><i>last page</i></small></a> ';
$pag2->link_active = ' <big><b>@num@</b></big> ';

echo
$pag2->links();
echo
"<br>".$pag2->size." rows displayed at ".$pag2->number_of_pages." pages"; // shjow links

//create nicer table
echo '<table rules="all" border="1px" style="background: black; color: orange">';
// first row of table - header
echo "<td style=\"padding: 10px\">ID</td><td style=\"padding: 10px\">NAME</td><td style=\"padding: 10px\">BIRTH YEAR</td></tr>\n";

// create our own function that outputs one row af table the way we want
function print_row($w) {
    echo
"<tr bgcolor=\"#444444\">\n";
    echo
' <td><font color="yellow">'.$w['id']."</font></td>\n";
    echo
' <td><b><u>'.$w['name']."</u></b></td>\n";
    echo
' <td><i>'.$w['birth_year']."</i></td>\n";
    echo
"</tr>\n";
}

// show data using our function
$pag2->content("print_row");

echo
"</table>";

$pag2->save(); // AP

// thats all:)






//********** creating example data
$q1 = "CREATE TABLE example ( id int(11) NOT NULL auto_increment, name char(10) default NULL, birth_year int(11) default NULL, PRIMARY KEY (id))";
$q2 = "INSERT INTO `example` VALUES (1, 'Ann', 1982), (2, 'Ben', 1932), (3, 'Carol', 1973), (4, 'Donald', 1988), (5, 'Emma', 1872), (6, 'Fiodor', 1982), (7, 'George', 1892), (8, 'Hilary', 1992), (9, 'Ian', 2000), (10, 'John', 1990), (11, 'Kate', 1982), (12, 'Leo', 1909), (13, 'Maria', 1987), (14, 'Natalie', 2001)";

mysql_query($q1);
mysql_query($q2);


?>
<hr><br>

All SQL data after one-time loading from database is stored in the session. If you are not using session, don't worry - nothing bad will happen. In fact, you wont see any difference (maybe a little slower working with big amount of data).<br>
<br>
See this files source code to see how it is easy to use.
<hr>
<h2>Reload at first use (example data will be added to database)</h2>