Guardian-Mage Posted September 4, 2007 Share Posted September 4, 2007 I am developing some software that is backed my MySQL/PHP. I need it so that one of my sql statements will extract only rows 5 through 10. Here is what I have now #Now we need to fill that array $query1 = "SELECT news_id,news_name,news_created,news_poster,news_comments,news_read,news_content FROM portal_news ORDER BY ABS(news_id) DESC LIMIT " . PORTAL_DISPLAY_NEWS_MAX; $execute1 = mysql_query($query1) or die("Unable to execute MySQL Query 1 in /portal/index.php"); $x = 0; while ($row = mysql_fetch_row($execute1)) { $news[$x] = array($row[0],$row[1],$row[2],$row[3],$row[4],$row[5],$row[6]); #News ID $x++; } Where PORTAL_DISPLAY_NEWS_MAX = 5; This works fine to extract the latest 5 articles, but I need more control. Something like limit 5-10 Quote Link to comment https://forums.phpfreaks.com/topic/67905-solved-phpsql-limit-5-10-how-can-i-do-it/ Share on other sites More sharing options...
pocobueno1388 Posted September 4, 2007 Share Posted September 4, 2007 Try this: $query1 = "SELECT news_id,news_name,news_created,news_poster,news_comments,news_read,news_content FROM portal_news ORDER BY ABS(news_id) DESC LIMIT " . PORTAL_DISPLAY_NEWS_MAX.", 10"; Quote Link to comment https://forums.phpfreaks.com/topic/67905-solved-phpsql-limit-5-10-how-can-i-do-it/#findComment-341304 Share on other sites More sharing options...
Fadion Posted September 4, 2007 Share Posted September 4, 2007 it should be "LIMIT 5, 5" where the first paramater is the starting row and the second is the range. So u have rows 6, 7, 8, 9, 10 from the query. Quote Link to comment https://forums.phpfreaks.com/topic/67905-solved-phpsql-limit-5-10-how-can-i-do-it/#findComment-341332 Share on other sites More sharing options...
Guardian-Mage Posted September 4, 2007 Author Share Posted September 4, 2007 I figured that out on my own after that guy gave me the code, thanks anyway Quote Link to comment https://forums.phpfreaks.com/topic/67905-solved-phpsql-limit-5-10-how-can-i-do-it/#findComment-341433 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.