<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>View Records</title>
<link rel="stylesheet" type="text/css" href="css.css">
</head>
<body>
<?php
/*
VIEW-PAGINATED.PHP
Displays all data from 'players' table
This is a modified version of view.php that includes pagination
*/
// connect to the database
include('connect-db.php');
// number of results to show per page
$per_page = 10;
// figure out the total pages in the database
mysql_query("SET CHARACTER SET utf8");
$result = mysql_query("SELECT * FROM vlekachi,evropa_otchet where vlekachi.vlekach=evropa_otchet.reg_nomer");
$total_results = mysql_num_rows($result);
$total_pages = ceil($total_results / $per_page);
// check if the 'page' variable is set in the URL (ex: view-paginated.php?page=1)
if (isset($_GET['section']) && is_numeric($_GET['section']))
{
$show_page = $_GET['section'];
// make sure the $show_page value is valid
if ($show_page > 0 && $show_page <= $total_pages)
{
$start = ($show_page -1) * $per_page;
$end = $start + $per_page;
}
else
{
// error - show first set of results
$start = 0;
$end = $per_page;
}
}
else
{
// if page isn't set, show first set of results
$start = 0;
$end = $per_page;
}
// dispaly add new record
echo "<p>" . "<a href=\"?page=new\">Добави нов запис" . "</a></p>";
// display data in table
echo "<table class=\"result\">";
echo "<tr> <th>Камион</th> <th>Начална дата</th> <th>Крайна дата</th><th></th> <th></th></tr>";
// loop through results of database query, displaying them in the table
for ($i = $start; $i < $end; $i++)
{
// make sure that PHP doesn't try to show results that don't exist
if ($i == $total_results) { break; }
// echo out the contents of each row into a table
echo "<tr>";
echo '<td>' . mysql_result($result, $i, 'reg_nomer') . '</td>';
echo '<td>' . mysql_result($result, $i, 'nach_data') . '</td>';
echo '<td>' . mysql_result($result, $i, 'kraina_data') . '</td>';
echo '<td><a href="?page=edit&id=' . mysql_result($result, $i, 'id') . '">Edit</a></td>';
echo '<td><a href="?page=delete&id=' . mysql_result($result, $i, 'id') . '">Delete</a></td>';
echo "</tr>";
}
// close table>
echo "</table>";
// pagination
// display pagination
echo "<br>";
echo "<b>Страница</b> ";
for ($i = 1; $i <= $total_pages; $i++)
{
echo "<a href='?page=view-paginated§ion=$i'>$i</a> ";
}
echo "</p>";
?>
</body>
</html>