Split Data Over Multiple Pages

Hi, I have a database that contains 35 record.
How do I split the data over multiple pages, whilst display a maximum of 5 records per page, at the same time of supplying page number links on each page, to enable the user to access the remaining records?

Example:

Display Record 1
Display Record 2
Display Record 3
Display Record 4
Display Record 5

Prev 1 2 3 4 5 6 7 Next

*Page two should display records 6-10, and so on.

TBIGC

Put “Limit 0,5” on the end of the Mysql query. That’ll show results from 0 to 5.
If you put “Limit 10,5” on the end of the query, It’ll show results from 10 to 15.
Look up Pagination, there are many resources to choose from.

On top of what arkinstall has already stated… Google “php paging” or “php pagination”… should yield some good results… In fact, I think Sitepoint has a few good articles about this… Here is one that talks about OOP paging towards end of article.

Good luck!
Cheers.

Hi

I came across the following code on the forums, posted by a user call TicTac.
How do I add numbered links to the script to represent the different available pages the user could navigate to.

Currently his/her script only consists of next and previous buttons.
Obviously, I need to change a few details in this script, in order for it to work for me.

His/Her Code is as follows:

<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
  die('Could not connect: ' . mysql_error());
}

mysql_select_db("WB", $con);

$perpage = 8;

$start = (isset($_GET['id'])) ? $_GET['id'] : 0;

$TotalRec = mysql_result(mysql_query("SELECT COUNT(*) FROM Data"), 0);

$select = "SELECT * FROM Data LIMIT $start, $perpage";
$result = mysql_query($select) or die(mysql_error());

while($row = mysql_fetch_array($result))
{
  echo $row['Name'] . '<br>';
  echo $row['Species'] . '<br>';
  echo $row['Sex'] . '<br><br>';
}

if($start == 0)
{
  echo "Previous Screen";
}
else
{
  echo '<a href='."./Display.php?id=" . ($start - $perpage) . '>'."Previous Screen".'</a>';
}

if($start + $perpage >= $TotalRec)
{
  echo "Next Screen";
}
else
{
  echo '<a href='."./Display.php?id=" . ($start + $perpage) . '>'."Next Screen".'</a>';
}
?>

TheBIGCube

Funnily enough, that’s the same thing TicTac (he of many names) was asking.

To be honest, it’d just be better if you construct it youself - fairly simple logic, putting it into code will be good practice for you.

I got the code from TicTac.

TheBIGCube.