i want to display the results of a sql statement in several pages
i have 6 rows .and i set the page limit to 2 rows
so i have 3 pages
i followed some tutorial online :
http://php.about.com/od/phpwithmysql/ss/php_pagination_3.htm
but when i click next i have no results to display !!
the while loop just selects the 1st 2 rows only ???
if (!(isset($pagenum)))
{
$pagenum = 1;
}
$data=mysql_query("select title from news ");
$rows = mysql_num_rows($data);
$page_rows = 2; //assuming 2 titles per page
$last = ceil($rows/$page_rows); //or last page
//this makes sure the page number isn't below one, or more than our maximum pages
if ($pagenum < 1)
{
$pagenum = 1;
}
elseif ($pagenum > $last)
{
$pagenum = $last;
}
//This sets the range to display in our query
$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;
$data_p = mysql_query("SELECT * from news $max");
echo "<table border='2' align='center' height='80%' width='80%' >";
while($row = mysql_fetch_array( $data_p ))
{
$id=$row["id"];
echo "<tr>";
echo "<td>";
echo "<LI>".$row["title"];
echo "</td>";
echo"<td> <a href='edit_news.php?id=$id'> Edit"; echo "</td>";
echo"<td><a href='#' onClick='confirm_delete($id)'> Delete</LI>"; echo "</td>";
echo"</tr>";
}
// 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='{$_SERVER['PHP_SELF']}?pagenum=1'> <<-First</a> ";
echo " ";
$previous = $pagenum-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'> <-Previous</a> ";
}
//just a spacer
echo " ---- ";
//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='{$_SERVER['PHP_SELF']}?pagenum=$next'>Next -></a> ";
echo " ";
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$last'>Last ->></a> ";
}