Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
<?php
/* Data paging script
2006-01-11 by sleipnir214
This script is in the public domain.
CAUTION: This script works on my system -- but it could blow yours to
smithereens. Therefore, no waranty is expressed or implied as to how
safe it will be for you to use.
Use this code with trepidation and circumspection.
*/
//variables for connecting to MySQL
$mysql_host = 'localhost';
$mysql_user = 'test';
$mysql_pass = 'test';
$mysql_db = 'test';
//set the number of records per page
$records_per_page = 10;
//connect to MySQL
mysql_connect ($mysql_host, $mysql_user, $mysql_pass);
mysql_select_db ($mysql_db);
//find out how many records are in the table
$count_query = "SELECT count(*) from words";
$rh = mysql_query ($count_query);
list ($record_count) = mysql_fetch_array($rh);
//calculate the maximum "page" that can be displayed.
$max_pages = floor($record_count / $records_per_page);
//This logic takes care of reacting to input.
if (isset($_GET['page']))
{
if ($_GET['page'] > 1)
{
if ($_GET['page'] > $max_pages)
{
$current_page = $max_pages;
}
else
{
$current_page = $_GET['page'];
}
}
else
{
$current_page = 1;
}
}
else
{
$current_page = 1;
}
$limit_start = ($current_page - 1) * $records_per_page;
//query the database for the required records
$data_query = "SELECT * FROM words LIMIT " . $limit_start . ", " . $records_per_page;
$rh = mysql_query ($data_query);
print '<html><body><table width="100%" border="1">';
//output the required records
while ($word_data = mysql_fetch_array($rh))
{
print '<tr>';
print '<td align="center" width="50%">' . $word_data['pkID'] . '</td>';
print '<td align="center" width="50%">' . $word_data['word'] . '</td>';
print '</tr>';
}
//this is the logic for the "previous" link display
print '<tr><td width="50%" align="center">';
if ($current_page > 1)
{
print '<a href="' . $_SERVER['PHP_SELF'] . '?page=' . ($current_page - 1) . '">previous</a>';
}
else
{
print ' ';
}
print '</td>';
//this is the logic for the "next" link display
print '<td width="50%" align="center">';
if ($limit_start + $records_per_page < $record_count)
{
print '<a href="' . $_SERVER['PHP_SELF'] . '?page=' . ($current_page + 1) . '">next</a>';
}
else
{
print ' ';
}
print '</td></tr></table><body></html>';
?>