how do i get results x through y

Discussion in 'Databases' started by mberman84, Jun 14, 2010.

  1. #1
    im trying to do something like this:

    $query = "SELECT * FROM likes LIMIT $begin,$end";


    I want to get results $begin through $end.

    for example, $begin can be 0 and $end would be 15. I am trying to say give me rows 15 through 30. how do i do that using variables in sql?
     
    mberman84, Jun 14, 2010 IP
  2. NemoPlus

    NemoPlus Peon

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hello,

    Your query is more or less OK. Only small mistake is that the second parameter is not the "end", but the number of results. For example,
    SELECT * FROM mytable LIMIT 5,10;  # will retrieve rows 6-15
    Code (markup):
    This means that if you want to retrieve all rows from 15 to 30 (included), that you need the query
    SELECT * FROM mytable LIMIT 14,16; 
    Code (markup):
     
    NemoPlus, Jun 15, 2010 IP
  3. saviola

    saviola Peon

    Messages:
    17
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You can see more information and examples here about LIMIT clause
     
    saviola, Jun 17, 2010 IP