Hello. I'm working on re-writing an old tagboard script so it works with register_globals = Off. Along with that, i'm trying to work out a bug in a pagination script. It displays the previous and next links correctly but it doesn't display the page number as being correct.
Any help with this is greatly appreciated!
<?php
#
# Page loaded in seconds script: part i
#
function timer() {
$time = explode(" ", microtime());
return $time[1] + $time[0];
}
$starttime = timer();
#
# Including the database configuration
#
include("./CONFIG/dbcnx.php");
#
# Defaulting $tags
#
$tags = $_GET['tags'];
if(!isset($tags)) $tags = "0";
#
# Grabbing the desired amount of 'tags' to be displayed
#
$query = 'SELECT * FROM tagit ORDER BY id DESC LIMIT ' . $tags . ', ' . $tagsToDisplay . ' ';
#
# Beginning the HTML Table 'tags' will be displayed in.
#
echo "<!-- TagIt! Tagboard $tagitversion -->\n\n"
?>
<table width="100%" border="0" cellpadding="4" cellspacing="0">
<?php
#
# Processing & error checking $query
#
$result = mysql_query($query);
if (!$result) die ("Whoops. An error occurred: <br />Reason: " . mysql_error() . "");
#
# Counting total amount of 'tags' in database
#
$rowcount = mysql_num_rows($result);
echo "\n<!-- There are $rowcount tags to display -->\n";
#
# Setting a variable for alternating row colors.
#
$row_count = "0";
#
# Looping through the results
#
while($r=mysql_fetch_array($result))
{
#
# Setting variables for row data; for the sake of ease.
#
$tagitnames=$r['tagitname'];
$tagiturl=$r['tagiturl'];
$tagitpost=$r['tagitpost'];
$tagitdate=$r['tagitdate'];
$tagitip=$r['tagitip'];
$id=$r['id'];
#
# Deciding which background color to use.
#
$row_color = ($row_count % 2) ? $bgColor1 : $bgColor2;
#
# Formatting and Filtering 'tags'
#
include("$extrafolder/txtformatting/special.php");
#
# Displaying 'tags'
#
?>
<tr>
<td bgColor=<?=$row_color;?>>
<b><a href="<?php if(stristr($tagiturl, "http://")) { echo "$tagiturl"; } else { echo "$protocol$tagiturl"; } ?>" target="_blank" title="<?php echo "Posted: $tagitdate"; ?>">
<?php echo "$tagitnames"; ?></a></b>:
<?php echo "$tagitpost"; ?>
</tr>
</td>
<?php
#
# Add 1 to $row_count
# End WHILE loop
#
$row_count++;
}
#
# Close the table tag
#
?>
</table>
<?php
#
# Displaying prev & next links
#
echo "<div align=\"center\">";
$query = "SELECT count(*) as count FROM tagit";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
$numRows = $row['count'];
$pageNums = intval ($numRows/$tagsToDisplay);
if($tags == "0") { $PageNowViewing = $tags+1; }
else { $PageNowViewing = intval ($tags*$pageNums/$numRows); }
if($tags > 0) {
echo "<a href=\"" . $_SERVER[PHP_SELF] . "?tags=" . ($tags - $tagsToDisplay) .
"\" ><<</a> ";
}
echo "Page $PageNowViewing of $pageNums ";
if($numRows > ($tags + $tagsToDisplay)) {
echo "<a href=\"" . $_SERVER[PHP_SELF] . "?tags=" . ($tags + $tagsToDisplay) .
"\" >>></a>";
}
#
# Page loaded in seconds script: part ii
#
$endtime = timer();
$loadtime = $endtime - $starttime;
$loadtime = number_format($loadtime, 7);
echo "\n\n<!-- Page loaded in $loadtime seconds. -->";
?>