I'm using a PHP script to paginate results from a db query over a number of pages. The only thing is that the "Next" and "Last" links for additional results don't seem to work at all (they just return the same page, i.e page 1).

Also I need to figure how I can modify this script so that it shows pages 1 to 4 as well as a First, Last, Prev and Next.

This is the current script:

<?php
include ('manager/special_offers/inc/dbconnect.php');

//This checks to see if there is a page number. If not, it will set it to page 1
if (!(isset($pagenum)))
{
$pagenum = 1;
}

// Build SQL Query
$data = mysql_query("select * from specialofferstable WHERE category like 'hotel' ORDER BY price") or die(mysql_error()); // specify the table and field names for the SQL query
//$numresults=mysql_query($query);
// get results
//$result = mysql_query($query) or die("Couldn't execute query");

$rows = mysql_num_rows($data);

//This is the number of results displayed per page
$page_rows = 15;

//This tells us the page number of our last page
$last = ceil($rows/$page_rows);

//This is your query again, the same one... the only difference is we add $max into it
$data_p = mysql_query("select * from specialofferstable WHERE category like 'hotel' ORDER BY price $max") or die(mysql_error());

$count++ ;
}
// This shows the user what page they are on, and the total number of pages
echo "Page $pagenum of $last<p>";

// First we check if we are on page one. If we are then we don't need a link to the previous page or the first page so we do nothing. If we aren't then we generate links to the first page, and to the previous page.
if ($pagenum == 1)
{
}
else
{
echo " <a href='specialoffers.html?pagenum=1'> << First</a> ";
echo " ";
$previous = $pagenum-1;
echo " <a href='specialoffersall.html?pagenum=$previous'> << Previous</a> ";
}

//This does the same as above, only checking if we are on the last page, and then generating the Next and Last links
if ($pagenum == $last)
{
}
else {
$next = $pagenum+1;
echo " <a href='specialoffersall.html?pagenum=$next'>Next >></a> ";
echo " ";
echo " <a href='specialoffersall.html?pagenum=$last'>Last >></a> ";
}