dsaba Posted April 24, 2007 Share Posted April 24, 2007 I'm running a query, it returns 9 rows in sql language that's: rows#0-8 I want to get the last row only i tried this: LIMIT 9, 9 also tried this: LIMIT 9, 1 Whenever I tried to access a particular row, this usually works fine for me: LIMIT 8, 8 please don't tell me to use mysql_result, because in my situation i need to access rows with mysql_query from the manual: The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT takes one or two numeric arguments, which must both be non-negative integer constants (except when using prepared statements). With two arguments, the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1): SELECT * FROM tbl LIMIT 5,10; # Retrieve rows 6-15 To retrieve all rows from a certain offset up to the end of the result set, you can use some large number for the second parameter. This statement retrieves all rows from the 96th row to the last: SELECT * FROM tbl LIMIT 95,18446744073709551615; With one argument, the value specifies the number of rows to return from the beginning of the result set: SELECT * FROM tbl LIMIT 5; # Retrieve first 5 rows so how do I do it? -thanks Link to comment https://forums.phpfreaks.com/topic/48395-solved-how-to-limit-the-last-row-of-your-query/ Share on other sites More sharing options...
Glyde Posted April 24, 2007 Share Posted April 24, 2007 LIMIT 8, 1 Link to comment https://forums.phpfreaks.com/topic/48395-solved-how-to-limit-the-last-row-of-your-query/#findComment-236641 Share on other sites More sharing options...
dsaba Posted April 24, 2007 Author Share Posted April 24, 2007 so LIMIT 8, 1 //displays row #9 ? and what displays row# 8? Link to comment https://forums.phpfreaks.com/topic/48395-solved-how-to-limit-the-last-row-of-your-query/#findComment-236643 Share on other sites More sharing options...
Glyde Posted April 24, 2007 Share Posted April 24, 2007 LIMIT 7, 1 You said it in your original post. "in sql language that's: rows#0-8." mySQL row results work like PHP arrays in the sense that the index begins from 0. Row 1 to a human is actually row 0 to the database. Link to comment https://forums.phpfreaks.com/topic/48395-solved-how-to-limit-the-last-row-of-your-query/#findComment-236646 Share on other sites More sharing options...
dsaba Posted April 24, 2007 Author Share Posted April 24, 2007 thanks for the help! someone told me something wrong with LIMIT syntax before and yeah i forgot what i wrote in my original post, my bad you cleared it up Link to comment https://forums.phpfreaks.com/topic/48395-solved-how-to-limit-the-last-row-of-your-query/#findComment-236650 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.