HI folks,
I have a problem with my pagination, let me show you the code first:
<?php
include("misc.inc.php");
$cxn = mysqli_connect($host,$user,$passwd,$dbname)
or die ("couldn’t connect to server");
if (isset($GET["page"])) {$page = $_GET["page"]; }
else {$page=1; };
$start_from = ($page-1) * 5;
$sql = "SELECT * FROM sport2 ORDER BY createDate DESC LIMIT $start_from, 5";
$result = mysqli_query ($cxn, $sql);
echo "<table cellspacing='5' border='0' cellpadding='5'
width='75%'>";
echo "<tr><td colspan='3' style='text-align: left'>
Welcome to the sports gallery. <hr /></td></tr>\n";
while($row = mysqli_fetch_assoc($result))
{
echo "<tr>";
echo "<td><img src='/images/sport/{$row['picture']}' border ='1' width='150' height=150'></td>";
echo "<td>{$row['loginName']}</td>";
echo "<td>{$row['createDate']}</td>";
echo "</tr>";
}
echo "</table>";
?>
<?php
$sql = "SELECT * FROM sport2";
$result = mysqli_query($cxn, $sql);
while($row = mysqli_fetch_row($result)){
$total_records = $row[0];
$total_pages = ceil($total_records / 5);
}
for ($i=1; $i<=$total_pages; $i++) {
echo "<a href='sport.php?page=".$i."'>".$i."</a> ";
};
?>
So the first program displays the data and the second program creates seperate pages to display the results.
The problem is that the same first 5 results are shown on every page. Ive been trying to work it out but just cant.
Any help would be much appreciated.
Thanx
Eazygo