Prev and Next Buttons not functioning mysql data SOLVED
Posted: Sat Mar 03, 2012 4:14 am
First of all thanks to everyone for taking the time if you are reading this. I have some code that displays 3 rows from mysql database and then below it are the prev and next buttons and they work and it shows the proper number of pages that are needed for all the rows in the table but when you click on the nav buttons they dont actually do anything. the page reloads and the URL seems correct but the results shown on the screen never actually change. You can look at my page at http://theproofstation.com/fishing if you need to see what Im trying to accomplish. I have to give the credit to himerus at daniweb.com for the code as I have edited only about 5% and it would be awesome if only it worked.
Thanks
Thanks
Code: Select all
<?
$server = "localhost";
$user = "root";
$pass = "";
$databasename = "proofstation";
$db = mysql_connect($server, $user, $pass);
mysql_select_db($databasename,$db);
$sql = "SELECT * FROM Main ORDER BY id DESC ";
$query = mysql_query($sql,$db);
$total_results = mysql_num_rows($query);
$limit = "3"; //limit of archived results per page.
$total_pages = ceil($total_results / $limit); //total number of pages
if (empty($page))
{
$page = "1"; //default page if none is selected
}
$offset = ($page - 1) * $limit; //starting number for displaying results out of DB
$query = "SELECT * FROM Main ORDER BY id DESC LIMIT $offset, $limit";
$result = mysql_query($query);
//This is the start of the normal results...
?>
<table><tr>
<?
while ($objResult = mysql_fetch_array($result))
{
?>
<td width="260">
<form enctype="multipart/form-data" name="fishingdetails" action="fishingdetails" method="post">
<input type="hidden" name="id" value=<?=$objResult["id"];?>>
<center><input type="image" src="http://theproofstation.com/upload/<?=$objResult["fishingphoto"];?>" border="0" width="150" alt="Submit" /></a><BR>
<b><?=$objResult["fishingname"];?> <BR></b> <?=$objResult["postercity"];?>, <?=$objResult["posterstate"];?><BR><?=$objResult["fishingdate"];?><BR>
<?=$objResult["fishingdescription"];?></form><BR></center></td>
<?
}
?>
</tr></table>
<?
mysql_close();
// This is the Previous/Next Navigation
echo "<font face=Verdana size=3><center>";
echo "<BR>Pages:($total_pages) "; // total pages
if ($page != 1)
{
echo "<a href=$PHP_SELF?page=1><< First</a> "; // First Page Link
$prevpage = $page - 1;
echo " <a href=$PHP_SELF?page=$prevpage><<</a> "; // Previous Page Link
}
if ($page == $total_pages)
{
$to = $total_pages;
}
elseif ($page == $total_pages-1)
{
$to = $page+1;
}
elseif ($page == $total_pages-2)
{
$to = $page+2;
}
else
{
$to = $page+3;
}
if ($page == 1 || $page == 2 || $page == 3)
{
$from = 1;
}
else
{
$from = $page-3;
}
for ($i = $from; $i <= $to; $i++)
{
if ($i == $total_results) $to=$total_results;
if ($i != $page)
{
echo "<a href=$PHP_SELF?showold=yes&page=$i>$i</a>";
}
else
{
echo "<b><font face=Verdana size=2>[$i]</font></b>";
}
if ($i != $total_pages)
echo " ";
}
if ($page != $total_pages)
{
$nextpage = $page + 1;
echo " <a href=$PHP_SELF?page=$nextpage>>></a> "; // Next Page Link
echo " <a href=$PHP_SELF?page=$total_pages>Last >></center><BR></a>"; // Last Page Link
}
echo "</font>";
// This is the end of the Previous/Next Navigation
?>