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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.