user1826795
user1826795

Reputation: 195

How to retrieve all rows from a certain offset up to a certain limit?

Here is my problem, so far I got this script:

$result = mysql_query(
    "SELECT *
       FROM $tableVideos
   ORDER BY VideoTimestamp DESC
      LIMIT 6"
) or die(mysql_error());

And that will make it so that I can show the 6 newest uploaded videos to my site.

But how can I have a limit of 6 and start from the 6th newest video and go up to the 12th? In that way I could show 6 videos and make a next button to show the next 6 videos.

Upvotes: 1

Views: 94

Answers (4)

Vikram Jain
Vikram Jain

Reputation: 5588

   Actually Limit function have two paramter : 
     one is limit of record and second is start from where.

    result = mysql_query("SELECT * FROM $tableVideos ORDER 
                          BY VideoTimestamp DESC LIMIT 6,6") or die(mysql_error());

Upvotes: 0

harikrishnan.n0077
harikrishnan.n0077

Reputation: 2047

Use this:

$result = mysql_query("SELECT * FROM $tableVideos ORDER BY VideoTimestamp DESC LIMIT 6,6") or die(mysql_error());

Upvotes: 0

Madara's Ghost
Madara's Ghost

Reputation: 174957

You want

LIMIT 6,6

Meaning "Start with the 6th entry, and give me 6 more".

Read more about it.

Upvotes: 4

borrible
borrible

Reputation: 17336

You currently have LIMIT 6 to get the first 6 results. If you use

LIMIT a,b

then you will get b items starting from the ath.

Upvotes: 5

Related Questions