a LIMIT question.

Discussion in 'MySQL' started by mahmood, May 9, 2006.

  1. #1
    in this statement:
    How can I make "y" the total number of all rows, so that mysql selects all rows from x to the end of the table?

    .
     
    mahmood, May 9, 2006 IP
  2. MrSupplier

    MrSupplier Peon

    Messages:
    141
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can use something like where `id` > x probably
     
    MrSupplier, May 9, 2006 IP
  3. Danny

    Danny Active Member

    Messages:
    732
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    78
    #3
    Above is correct.

    buy it would exclude x and the original author wants x included

    Try
    $x = $x-1;
    select * from table where id>$x

    not perfect but right now it will work for you. You cna do it in pure SQL if you can be bothered but the milisecond performance increase isnt worth it
     
    Danny, May 9, 2006 IP
  4. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,334
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #4
    You can set it to something absurdly high... like LIMIT x,999999999999
     
    digitalpoint, May 10, 2006 IP
  5. mahmood

    mahmood Guest

    Messages:
    1,228
    Likes Received:
    43
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks for replies.
    I will go with this one since the table doesn't have an incremental id.
     
    mahmood, May 10, 2006 IP
  6. ajayr

    ajayr Active Member

    Messages:
    322
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    58
    #6
    Actually, in a DB, the rows are not stored in any particular order. So unless you are sorting the results based on some field, there are no "last x rows" in a table.
     
    ajayr, May 10, 2006 IP
  7. MrSupplier

    MrSupplier Peon

    Messages:
    141
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Hope you have PK because results will be shuffled each time)))
     
    MrSupplier, May 10, 2006 IP
  8. dddougal

    dddougal Well-Known Member

    Messages:
    676
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    108
    #8
    or you can use numrows, then you will know how many records there are:

    $query = "SELECT * FROM mytable ORDER BY whatever" //order by will make sure you get the same results every time
    $result = @mysql_query ($query);
    $numrows = mysql_num_rows($result);

    '$numrows' then contains the number of rows in the table.
     
    dddougal, May 15, 2006 IP