Hi i have MySql Table with 25 rows and i want to display first 10 rows in a page using PHP.. When i Click the next button it shows another 10 rows from table and so on...Help Me. Thank you..
Very broad question, but the basics are it can be solved with the "LIMIT" MySQL command. Basically your PHP code detects if someone has gone to another page and then when it makes it's query, the "LIMIT" is adjusted. So for page 1, the "LIMIT" in this MySQL pseudocode would be:
SELECT * FROM {my table} WHERE {criteria is this} LIMIT 0,10
And for page 2 the "LIMIT" would be something like this:
SELECT * FROM {my table} WHERE {criteria is this} LIMIT 11,20
As for the PHP pagination, you would have to come up with some logic. Perhaps—and most traditionally—passing a URL variable via POST such as:
http://localhost/index.php?pn=2
Then your PHP logic does some math to determine the start & end of the range. So in this example maybe do something like:
$pn = $GET['pn'];
$per_page = 10;
$bottom_limit = (($pn*$per_page)-$per_page)+1);
$top_limit = ($pn*$per_page);
And then in PHP the LIMIT would be placed along the lines of:
$limit = " LIMIT " . $bottom_limit . ", " . $top_limit;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With