shahzad Posted February 3, 2010 Share Posted February 3, 2010 i have a table name "News" I want to fetch records from 6 onwards what will be the query for it. for example if table news have 10 records what i want is to fetch record 6 to 10 or we can say skip first 5 records. Thanks in advance Regards, Shahzad Quote Link to comment https://forums.phpfreaks.com/topic/190759-mysql-query/ Share on other sites More sharing options...
jl5501 Posted February 3, 2010 Share Posted February 3, 2010 You use the limit on the end of your query like select * from mytable limit 5,6 says skip 5 then give me the next 6 Quote Link to comment https://forums.phpfreaks.com/topic/190759-mysql-query/#findComment-1005950 Share on other sites More sharing options...
PravinS Posted February 3, 2010 Share Posted February 3, 2010 Try this $sql = "SELECT * from TABLENAME LIMIT 6, 5"; it will give you next 5 records from 6 to 10 Quote Link to comment https://forums.phpfreaks.com/topic/190759-mysql-query/#findComment-1005951 Share on other sites More sharing options...
shahzad Posted February 3, 2010 Author Share Posted February 3, 2010 ok thanks 1 more thing now as it is news table i dont know how many record it will have at that point of time but everytime i will display news in front end i need to skip 5 record and display all.. so there is a way where i can tell skip first 5 and get all records?? thanks again Quote Link to comment https://forums.phpfreaks.com/topic/190759-mysql-query/#findComment-1005953 Share on other sites More sharing options...
jl5501 Posted February 3, 2010 Share Posted February 3, 2010 yes select * from mytable limit 5 Quote Link to comment https://forums.phpfreaks.com/topic/190759-mysql-query/#findComment-1005956 Share on other sites More sharing options...
jl5501 Posted February 3, 2010 Share Posted February 3, 2010 sorry select * from mytable skip 5 Quote Link to comment https://forums.phpfreaks.com/topic/190759-mysql-query/#findComment-1005957 Share on other sites More sharing options...
PravinS Posted February 3, 2010 Share Posted February 3, 2010 You can calculate total number of records in the table and then subtract 5 from it the your query will change as $displayrecords = $totalrecords - 5; $sql = "SELECT * from TABLENAME LIMIT 6, $displayrecords "; Quote Link to comment https://forums.phpfreaks.com/topic/190759-mysql-query/#findComment-1005958 Share on other sites More sharing options...
jl5501 Posted February 3, 2010 Share Posted February 3, 2010 I will wake up in a minute select * from mytable offset 5 Quote Link to comment https://forums.phpfreaks.com/topic/190759-mysql-query/#findComment-1005959 Share on other sites More sharing options...
shahzad Posted February 3, 2010 Author Share Posted February 3, 2010 Thaks pbs it works jl5501 i tried offset but i am getting an error. i think offset is not valid without limit... thankyou guys Quote Link to comment https://forums.phpfreaks.com/topic/190759-mysql-query/#findComment-1005963 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.