PHP Table With Next Arrow

Good afternoon, I am running a SQL Query and returning the results to a HTML table. This returns roughly 200 rows, and the data is returned in about .5 seconds. This requires a great deal of scrolling, is there a way to (and I am not sure of the terminology) show the first 50 records in the table, and have an arrow at the bottom that when clicked will show the next 50 records?

yes, what you’re talking about it called pagination.

whilst you can write the code needed to to work out how many pages to show per page and to determine how many page links to create I think it’s best to use a reuseable class that way you can include a file and have pagination up and running quickly.

I’ve written a pagination class https://github.com/daveismyname/pagination

To use it:

[php]
//include the class
include(‘paginator.php’);

//create new object pass in number of pages and identifier
$pages = new Paginator(‘50’,‘p’);

//get number of total records
$rows = $db->query(‘SELECT id FROM table’);
$total = count($rows);

//pass number of records to
$pages->set_total($total);

$data = $db->query('SELECT * FROM table '.$pages->get_limit());
foreach($data as $row) {
//display the records here
}

//create the page links
echo $pages->page_links();
[/php]

[member=24336]daveismyname[/member] - that was excellent, thank you!

Sponsor our Newsletter | Privacy Policy | Terms of Service