• 0

PHP limiting results per page


Question

i have a page which displayes records from a mysql database, but i want to limit it to only 10 records and then beable to advance trhoguth them in sets of 10,

anyone know where i can find some example code of this? or a better idea of how to do it

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

$limit= records per page

$pn=page user requested

$pages = number of pages from a full query

"SELECT count(whatever) as count FROM table WHERE blah;

//This query just got us the total number or records found

$pages = ceil($result_of_query / $limit);

//Set up the start point for archives, eg article 1,25,50,75,etc.

$start = $pn * $limit - $limit

$query = "SELECT * FROM table WHERE blah LIMIT " . $start . "," . $limit;

//This gets you the selected records from 1-10, 11-20, whatever

That's it...just print out the page pagination on the page and you're done.

Edit:

Here's the pagination too

for ($loopcount = 1; $loopcount <= $pages; $loopcount++)

{

echo "<a href='/link/to/page.php?pn=$loopcount'>";

}

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.