nahla123 Posted April 6, 2008 Share Posted April 6, 2008 hi could any one please tell me how to get the current row number when selecting rows from database i mean if i have 10 rows i can read only the third for example Quote Link to comment https://forums.phpfreaks.com/topic/99776-how-to-get-the-current-row-number/ Share on other sites More sharing options...
p2grace Posted April 6, 2008 Share Posted April 6, 2008 What? Are you trying to select the last id in the db table, or are you trying to know what the id was of your last insert statement? I guess rephrase the question so we can better assist. Quote Link to comment https://forums.phpfreaks.com/topic/99776-how-to-get-the-current-row-number/#findComment-510287 Share on other sites More sharing options...
budimir Posted April 6, 2008 Share Posted April 6, 2008 If I understand correctly, you will need to select an ID of the row you want to display. So, for example, if you want to display row number 3 (out of 10). You will need to do a query like $sql = mysql_query("SELECT * FROM tblName WHRE id = '3'") or die (mysql_error()); This peace of code would display a row where ID = 3 (so, if prepared like I assume, it would be a row number 3). But, again, it's hard to understand what are you asking for. Quote Link to comment https://forums.phpfreaks.com/topic/99776-how-to-get-the-current-row-number/#findComment-510375 Share on other sites More sharing options...
nahla123 Posted April 6, 2008 Author Share Posted April 6, 2008 i mean if i had 10 rows for example and i wanna make some type of pagination by reading the first five and by cliking next read the last , so how can i stop at the fifth one , i want some thing to get me the row number to know that i reached the fifth. Quote Link to comment https://forums.phpfreaks.com/topic/99776-how-to-get-the-current-row-number/#findComment-510377 Share on other sites More sharing options...
uniflare Posted April 6, 2008 Share Posted April 6, 2008 mysql pagination is used with LIMIT, eg: SELECT * FROM `table` LIMIT 0,15; SELECT * FROM `table` LIMIT 15,15; SELECT * FROM `table` LIMIT 30,15; where the first number is the row OFFSET, eg how many rows to SKIP. the second number is the MAX ROWS, how many rows it can count to until it stops. hope this helps, Quote Link to comment https://forums.phpfreaks.com/topic/99776-how-to-get-the-current-row-number/#findComment-510413 Share on other sites More sharing options...
uniflare Posted April 6, 2008 Share Posted April 6, 2008 http://dev.mysql.com/doc/refman/4.1/en/select.html for detailed information Quote Link to comment https://forums.phpfreaks.com/topic/99776-how-to-get-the-current-row-number/#findComment-510414 Share on other sites More sharing options...
Barand Posted April 6, 2008 Share Posted April 6, 2008 In general, if R = rows per page and P is the page number (1,2,3 etc) N = (P-1) * R so ... LIMIT N, R Quote Link to comment https://forums.phpfreaks.com/topic/99776-how-to-get-the-current-row-number/#findComment-510419 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.