JamesCliff
Programmer
Hi all,
Right i have finished my site, however im doing some upgrades as requested by my client. He wants to have a certain number of records per page and then next and previous buttons. So i found a script and implemented it into my script which ive posted below:-
Now everything displays fine and looks good. The script is able to work out how many pages are needed and shows the links at the bottom of the page. I currently have 4 records in my database and have the limit on the script above set to 3. So therefore it displays page 1 and page 2 link. However when i click on a link to goto page 2 nothing happens, no records change or update or anything like that. It simply stays on the same page it started with displaying the first 3 records. However after the links have been clicked, the address bar does alter and page=2 is displayed, still dosnt work though.
Why is this?
You can see the problem for yourself at:
Click on the page links and see what happens.
Using the code i posted above, can anyone tell me whats wrong and or how it can be fixed?
Thanks alot
Jim
Right i have finished my site, however im doing some upgrades as requested by my client. He wants to have a certain number of records per page and then next and previous buttons. So i found a script and implemented it into my script which ive posted below:-
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?
session_start();
$host = "127.0.0.1";
$user = "jim11";
$pass = "";
$db = "gbplantandmachinery";
$connection = mysql_connect($host, $user, $pass) or die ("Unable to
connect!");
mysql_select_db($db) or die ("Unable to select database!");
if (!session_is_registered("salescounted")){
mysql_query("UPDATE salescounter SET count=(count + 1) WHERE count_id=1");
session_register("salescounted");
}
?>
<div align="center">
<table width="724">
<!--DWLayoutTable-->
<tr>
<td width="100%" height="261" valign="top"><div align="center">
<br>
<p><font size="2"><strong>sales</strong></font></p>
<p>Please contact us for any further information or pictures regarding<br>
a sales item in the list below.<br>
<br>
<a href="index.php?page=contact">Click here for contact information</a></p>
<p> </p>
<p>
<?
$server = "127.0.0.1";
$user = "jim11";
$pass = "";
$databasename = "gbplantandmachinery";
$db = mysql_connect($server, $user, $pass);
mysql_select_db($databasename,$db);
echo "<table>";
echo "<tr>
<td width='120'><strong>Photo</strong></td>
<td width='130'><strong>Make / Model</strong></td>
<td width='260'><strong>Description</strong></td>
<td width='120'><strong>Date Posted</strong></td>
<td width='110'><strong>Price</strong></td>
</tr>";
echo "<tr>";
echo '<td colspan="5"><hr /></td>
</tr>';
echo "<tr>";
echo '<td colspan="5"> </td>
</tr>';
echo "</table>";
$sql = "select `Image_Ref`, `Title`, `Description`, `Date`, `Price` from sales";
$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 `Image_Ref`, `Title`, `Description`, `Date`, `Price` from sales LIMIT $offset, $limit";
$rslt = mysql_query($query);
//This is the start of the normal results...
while ($result = mysql_fetch_array($rslt))
{
echo "<table>";
echo "<tr>";
echo '<td><img src="photos/' . $result['Image_Ref'] . '" width="100" height="75"></td> ';
echo '<td width="175">' . $result['Title'] . '</td>
<td width="250">' . $result['Description'] . '</td>
<td width="175">' . $result['Date'] . '</td>
<td width="100">' . $result['Price'] . '</td>
</tr>';
echo "<tr>";
echo "<td><a href=\"photos/" . $result['Image_Ref'] . "\" target=\"_blank\">Full Size Picture</a></td>";
echo "</tr>";
echo "<tr>";
echo '<td colspan="5"><hr /></td>
</tr>';
echo "</table>";
}
mysql_close();
// This is the Previous/Next Navigation
echo "<font face=Verdana size=1>";
echo "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 >></a>"; // Last Page Link
}
echo "</font>";
// This is the end of the Previous/Next Navigation
?>
<br>
</p>
</div></td>
</tr>
</table>
</div>
</body>
</html>
Now everything displays fine and looks good. The script is able to work out how many pages are needed and shows the links at the bottom of the page. I currently have 4 records in my database and have the limit on the script above set to 3. So therefore it displays page 1 and page 2 link. However when i click on a link to goto page 2 nothing happens, no records change or update or anything like that. It simply stays on the same page it started with displaying the first 3 records. However after the links have been clicked, the address bar does alter and page=2 is displayed, still dosnt work though.
Why is this?
You can see the problem for yourself at:
Click on the page links and see what happens.
Using the code i posted above, can anyone tell me whats wrong and or how it can be fixed?
Thanks alot
Jim