How would you do a query so php only grabs mysql tbl rows 100-200 ? Imagine tbl is called ‘users’ and you want to grab data from column ‘username’. How to do this ?
@NogDogMar 15.2019 — #You never grab by "row" -- you grab by some column. In this case, you probably grab by whatever the primary key column is, which I'll pretend is "id" for now: <i> </i>select * from my_table order by id limit 100 offset 100 ;
Look up "order by", "limit" and "offset" in the MySQL manual if that does not make sense to you.
Let's say, I got total 1000 rows and I want each pagination page displaying 100 rows each. In that case, when the user is shown the 1st pagination page then I should code the query like this following, right ? <i> </i>select * from my_table order by id limit 100 offset 0 ;
And when user clicks the 2nd page in the pagination then I get the 2nd page to make query like the following, correct ? <i> </i>select * from my_table order by id limit 100 offset 100 ;
Then get the 3rd page to query like .... <i> </i>select * from my_table order by id limit 100 offset 200 ;
Yes ?
On each page, I will have to query mysql again limiting the query to grab 100 rows and I give it the starting point for that particular page with the offset. Correct ? The offset gets raised by the limit per page or results per page number (in our case 100), right ?
If this is how you do it then I might aswell attempt my own shorter way of building a pagination page with mysqli using procedural style. No need for me to waste my nights again googling for a tutorial. I won't forget to use the ceil for rounding-up the numbers and I won;t forget to build a variable that calcs how many pages should be holding the total results in the pagination. So, don't worry about that.
However, if I'm missing anything then do speak up!
@NogDogApr 11.2019 — #That's the server-side-driven way to do it. The alternative is doing it on the client side, sending the entire result set to the page and allowing JavaScript (via one of the available pagination libraries, most likely) to handle the pagination. Either way has advantages and drawback, and I'm not suggesting either is better than the other.