I have a pagination script that has stopped working. Could somebody please take a look at it and suggest a fix please.
I know there is a lot of code but as it compiles and runs so no errors, but does not do page links successfully anymore I had to include the full script. Also, the SQL will need to be changed to another table's fields.
I know this is a hard question and will involve cutting and pasting into Dreamweaver (unless your an expert) but I would appreciate a fix because it is driving me crazy.
<?php
require "dbase.php"; //this script contains a database class
$dbcon=new db(); //instantiate db class
$dbcon->getConnection(); //get database connection
if (!($limit)){
$limit = 6;}
if (!($page)){
$page = 0;}
$numresults = $dbcon->getResultOf("SELECT event_tickets_booked, event_max_booking, eventID, event_name, event_start_date, event_venue, event_comments, event_town
FROM tblevents
WHERE event_expired = 'N'"); //and county = ''
$numrows = mysql_num_rows($numresults);
if ($numrows == 0){
echo("No results found matching your query - $query");
exit();}
$pages = $numrows/$limit;
// $pages now contains int of pages, unless there is a remainder from division.
if ($numrows%$limit) {
$pages++;} // has remainder so add one page
$current = intval($page/$limit) + 1; // Current page number.
if (($pages < 1) || ($pages == 0)) {
$total = 1;} // If $pages is less than one or equal to 0, total pages is 1.
else {
$total = $pages;} // Else total pages is $pages value.
$first = $page + 1; // The first result.
if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) {
$last = $page + $limit;} //If not last results page, last result equals $page plus $limit.
else{
$last = $numrows;} // If last results page, last result equals total number of results.
?>
<html>
<head>
<title>Search Results for <?=$query?></title>
<style type="text/css">
<!--
.style1 {font-size: 18px}
-->
</style>
</head>
<body>
<center>
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="171"><span class="style1" style="font-size: 18px;"><span class="style1" style="font-size: 18px;">
<?
if ($page != 0) { // Don't show back link if current page is first page.
$back_page = $page - $limit;
echo("<a href=\"$PHP_SELF?query=$query&page=$back_page&limit=$limit\">back</a> \n");}
for ($i=1; $i <= $pages; $i++) // loop through each page and give link to it.
{
$ppage = $limit*($i - 1);
if ($ppage == $page){
echo("<b>$i</b> \n");} // If current page don't give link, just text.
else{
echo("<a href=\"$PHP_SELF?query=$query&page=$ppage&limit=$limit\">$i</a> \n");}
}
if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { // If last page don't give next link.
$next_page = $page + $limit;
echo("<a href=\"$PHP_SELF?query=$query&page=$next_page&limit=$limit\">next</a>\n");}
?>
</span>
</span></td>
<td width="329"><span class="style1" style="font-size: 18px;">Events</span><span class="style1"> for</span>
<?=$query?></td>
</tr>
</table>
</center>
<table width="100%" border="0">
<tr>
<td width="50%" align="left">Results <b>
<?=$first?>
</b> - <b>
<?=$last?>
</b> of <b>
<?=$numrows?>
</b>
</td>
<td width="50%" align="right">
Page <b><?=$current?></b> of <b><?=$total?></b>
</td>
</tr>
<tr>
<td colspan="2" align="right">
</td>
</tr>
</table>
<?
// Now we can display results.
$results = $dbcon->getResultOf("SELECT event_tickets_booked, event_max_booking, eventID, event_name, event_start_date, event_venue, event_comments, event_town
FROM tblevents
WHERE event_expired = 'N'
ORDER BY eventID ASC
LIMIT $page, $limit"); //and event_county = %s
while ($data = mysql_fetch_array($results))
{
?>
<tr>
<td colspan="2" align="right"><div align="left">
<p><large><a href="../frmEventDetails.php"> <?php echo trim($data['event_name']); ?> </a>
<?php
if ($data['event_tickets_booked'] == $data['event_max_booking'])
{
echo "This Event is Fully Booked";
}
//echo "<img src=\"booked.gif\" alt=\"This show is fully booked\" width=\"20\" height=\"20\">\n";
?>
<br>
<font face="Arial">
<label></label>
<?php echo stripslashes($data['eventID']); ?> <br>
<font color='#0066CC'>Venue </font>
<label></label>
<span style="color: #000000"><?php echo stripslashes($data['event_venue']); ?></span><font color='#0066CC'> Address
<label></label>
</font><?php echo stripslashes($data['event_town']); ?> <br>
<font color='#0066CC'>Comments </font>
<label><span style="color: #000000"><?php echo stripslashes($data['event_comments']); ?></span></label>
</font></small> </p>
<form name="form2" method="post" action="../frmEventDetails.php">
<input name="ID" type="hidden" id="ID" value="<?php echo stripslashes($data['eventID']); ?>">
</form>
<small><font face="Arial"><label></label>
</font></small></div></td>
</tr>
<?
}
?>
<p><span class="style1" style="font-size: 18px;">
</span></p>
<p> </p>
<p align="center"> </p>
</body>
</html>