stuart.cole Posted October 10, 2006 Share Posted October 10, 2006 Hi I am building a news delivery site - with the news being delivered in 3 areas. The first should have the latest news item, the second area the second most recent item, and the third area, latest stories 3-7.How can I get PHP to select the last item, next to last, and then 3-7 since the ID's of these items will change as new items are added all the time?I know there is probably a very simple answer to this - but I've not found one yet :( Quote Link to comment https://forums.phpfreaks.com/topic/23561-dynamic-selection-of-content-ermm-help/ Share on other sites More sharing options...
HuggieBear Posted October 10, 2006 Share Posted October 10, 2006 Use the ORDER BY syntax in MySQL to get the stories ordered by date, and use the LIMIT syntax to restrict the number of requested rows.You can find a link to the MySQL manual in my signature.RegardsHuggie Quote Link to comment https://forums.phpfreaks.com/topic/23561-dynamic-selection-of-content-ermm-help/#findComment-106930 Share on other sites More sharing options...
shiny_spoon Posted October 10, 2006 Share Posted October 10, 2006 Like so:Area 1: Latest[code]<?php$query = 'SELECT * FROM "news" ORDER BY "date" DESC LIMIT 0,1';?>[/code]Area 2: 2nd Latest[code]<?php$query = 'SELECT * FROM "news" ORDER BY "date" DESC LIMIT 1,1';?>[/code]Area 3: Results 3 to 7[code]<?php$query = 'SELECT * FROM "news" ORDER BY "date" DESC LIMIT 2,5';?>[/code]...replacing [code=php:0]'news'[/code] and [code=php:0]'date'[/code] with whatever your columns are named. You might also want to read the suggested documentation to know how everything works. :) Quote Link to comment https://forums.phpfreaks.com/topic/23561-dynamic-selection-of-content-ermm-help/#findComment-106946 Share on other sites More sharing options...
stuart.cole Posted October 10, 2006 Author Share Posted October 10, 2006 Thanks both. It was the limit numbers that were confusing me - the rest was done but with your plain example I can see how that works now. Much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/23561-dynamic-selection-of-content-ermm-help/#findComment-106952 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.