Jump to content

How to echo mysql rows at certian point?


Cultureshock

Recommended Posts

(Basically this is for paginating data)...

 

Say I have a list of data 10 rows long, but I only want to show data rows 3-8 in my while statement. I use ?limit=5 (aka $limit = $_GET['limit']; ) to set the mysql query LIMIT $limit. But obviously this code shows rows 1-5.

 

If I use ?page=3&limit=5 (aka $limit = $_GET['limit'];$page = $_GET['page']; ), how would I print out only data rows starting at the third row? Is this something in the query or php?

Link to comment
https://forums.phpfreaks.com/topic/181182-how-to-echo-mysql-rows-at-certian-point/
Share on other sites

I'm not sure if I correctly understand, but here goes.

 

When you use LIMIT with MySQL queries, you can put one or two numbers afterwards. The first number is the row from which it should start, and the second number is the amount of rows it should count from the starting point (first number).

 

Example:

 

mysql_query("SELECT * FROM my_table LIMIT 5,5");

 

That will select all columns from 'my_table'. However, it will start at row 5 and take 5 rows from there, i.e., it will take rows 6, 7, 8, 9, 10.

 

 

mysql_query("SELECT * FROM my_table LIMIT 0,5");

That will get rows 1, 2, 3, 4, 5.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.