would it be possible to look at my paginating code?
it seems that when i navigate throughout the pages it seems to add another hit to the counter.
<?php
require('sql.php');
//How many records to show per page
$show = 20;
//Check to see if we've calulated the number of pages yet
if (isset($_GET['np'])) {
$num_pages = $_GET['np'];
} else {
//Count the number of total records in the database query using the COUNT() SQL function
$query = "SELECT COUNT(*) FROM tracker ORDER BY start ASC";
$result = mysql_query($query);
$row = mysql_fetch_array($result, MYSQL_NUM);
$num_records = $row[0];
//Calculate the number of pages required to show all the results
if ($num_records > $show) {
$num_pages = ceil($num_records/$show);
} else {
$num_pages = 1;
}
}
//Figure out the first record to return from the database
if (isset($_GET['s'])) {
$start = $_GET['s'];
} else {
$start = 0;
}
$sq = "SELECT id
FROM `tracker`
WHERE MONTH(timespan)=MONTH(NOW())
AND DAY(timespan)=DAY(NOW())
AND YEAR(timespan)=YEAR(NOW())
AND HOUR(timespan)=HOUR(NOW())
LIMIT 1";
$res = @mysql_query($sq);
if(!$r)
{
// No rows yet, we need to add the initial one
$q = "INSERT INTO `tracker` (home, start, end , timespan) VALUES ('','1','', NOW())";
}
else
{
// Already a row dealing with the current hour
// Specify Update query
$q = "UPDATE `tracker` SET start=start+1 WHERE id='".$r['id']."'";
}
// Define which action we're taking (Update or Insert);
$action = substr($q, 0, strpos($q, ' ', 0));
$action = ucwords(strtolower($action));
$res = @mysql_query($q);
if(!$res)
{
// Failed to update/insert
die('Failed to '.$action.' value(s) in <em>tracker</em>. MySQL gave the following information:<br><strong>Error #:</strong> '.mysql_errno().'<br><strong><em>Error :</em></strong> '.mysql_error());
}
else
{
$cq = "SELECT * FROM `tracker` ORDER BY id DESC LIMIT $start, $show";
$res = @mysql_query($cq);
// Successfully updated/inserted information
echo 'Successfully '.$action.'ed the value(s) in <em>tracker</em>. The table output is below:<br><br>';
echo "
<table border='1'>\n
\t<tr><th>id</th><th>home</th><th>start</th><th>end</th><th>timespan</th></tr>\n";
while($r = mysql_fetch_array($res))
{
echo "
\t<tr>\n
\t\t<td>".$r['id']."</td>\n
\t\t<td>".$r['home']."</td>\n
\t\t<td>".$r['start']."</td>\n
\t\t<td>".$r['end']."</td>\n
\t\t<td>".$r['timespan']."</td>\n
\t</tr>\n\n";
}
echo "
</table>";
}
//Make the numbered links for the other pages
if ($num_pages > 1 ) {
echo '<br><p>';
//Figure out what page the current script is now on
$current_page = ($start/$show) +1;
//Make a previous button if you are not on the first page of results
if ($current_page != 1 ) {
echo '<a href="run.php?s=' . ($start - $show) . '&np=' . $num_pages . '"><< </a>';
}
//Make all the numbered links
for ($i = 1; $i <= $num_pages; $i++) {
if ($i != $current_page) {
echo '<a href="run.php?s=' . (($show * ($i - 1))) . '&np=' . $num_pages . '">' . $i . '</a>';
} else {
echo $i . ' ';
}
}
//Make a next button if you are not on the last page of results
if ($current_page != $num_pages) {
echo '<a href="run.php?s=' . ($start + $show) . '&np=' . $num_pages . '"> >></a>';
}
echo '</p>';
}
?>