PHP Classes

File: mysql.php

Recommend this page to a friend!
  Classes of ted kappes  >  Paginator  >  mysql.php  >  Download  
File: mysql.php
Role: Documentation
Content type: text/plain
Description: mySQL use documentation
Class: Paginator
Spliting database query result sets between pages.
Author: By
Last change:
Date: 18 years ago
Size: 2,819 bytes


Class file image Download
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"

<title>mySQL Example</title>
<style type="text/css">
body { margin-top: 20px;
			 margin-left: 50px;
			 margin-right: 50px;
			 background-color: #FFFF99; 
			 font-family: Verdana;
h1 { font-size: 150%;
h2 { font-size: 125%;
<p><a href="index.php">Back to Index</a></p>
<h1>mySQL Example</h1>
<h2>Using Paginator with mySQL</h2>
<p>To divide mySQL result sets into pages you may do the following. I assume you
have made a connection to your database.</p>
<li><p>Include the Paginator class.<br />
<strong>include(</strong>"include/paginator.php"<strong>);</strong><br />
If you are using Paginator_html include that also.<br />
<li><p>Make a query to get the number of rows in your database. You might use somthing
like this.<br />
<strong>$num_rows = mysql_result(mysql_query("SELECT COUNT(*) FROM your table"),0);</strong></p></li>
<li><p>Make a new Paginator object<br/>
<strong>$a =& new Paginator(</strong>$_GET['page'],$num_rows<strong>);</strong><br />
If you are using Paginator_html make a new new Paginator_html object instead of a Paginator object.<br />
<strong>$a =& new Paginator_html(</strong>$_GET['page'],$num_rows<strong>);</strong></p></li>
<li>Set the number of records to be displayed<br />
<li><p>If using numbered links this will set the number before and behind 
		the current page.<br /><strong>$a->set_Links(3);</strong></p></li>
<li><p>Get the starting point.<br />
		<strong>$limit1 = $a->getRange1(); </strong><br /> 
		Get the number of items displayed on page.<br />
		<strong>$limit2 = $a->getRange2(); </strong></p> </li>
<li><p>Make your query using LIMIT<br />
<strong>$result=mysql_query("SELECT * FROM your table LIMIT $limit1, $limit2");</strong> </p></li>
<li><p>Output your results in your preferred manner</p></li>
<li><p>If you are using Paginator alone you will need to create your links here using the methods
from Paginator. See example3.php, example4.php, and the <a href="paginator_doc.php">Paginator info</a> for help in
using these methods</p>
<p>If you are using Paginator_html you add the methods to add your links here<br />
<strong>$a->firstLast();</strong><br />
Will make a set of links like this: 5 of 8 of 25 <u>First</u> | <u>Prev</u> | <u>Next</u> | <u>Last</u> |<br />
<strong>$a->previousNext();</strong><br />
Will make a set of links like this: <u>Previous</u> <u>1</u> <u>2</u> <u>3</u> 4 <u>5</u> <u>6</u> <u>7</u> <u>Next</u></p>
<p><a href="index.php">Back to Index</a></p>
For more information send a message to info at phpclasses dot org.