wrathican Posted June 28, 2007 Share Posted June 28, 2007 hey guys i want a news section on my website but i only want it to show the latest two entries. ive got my code sorted to go into the DB get the news items and display them, but i dont know how to cut it down to just the LATEST TWO entries. does it have anything to do with mysql order? any tips you could give me? Link to comment https://forums.phpfreaks.com/topic/57629-solved-php-news-section/ Share on other sites More sharing options...
biffyboy Posted June 28, 2007 Share Posted June 28, 2007 I assume you are using MySQL - if so add this to the end of your query: "LIMIT 0, 2" The first number is the record it starts at ("0" being the first row in your result) the second number is how many records it will grab. Link to comment https://forums.phpfreaks.com/topic/57629-solved-php-news-section/#findComment-285278 Share on other sites More sharing options...
no_one Posted June 28, 2007 Share Posted June 28, 2007 2 ways I think. Either each news item has a unique ID and we can assume newer == higher. Select * from news order by id DESC limit 2 or each has a date same idea, only change id to date.. Link to comment https://forums.phpfreaks.com/topic/57629-solved-php-news-section/#findComment-285279 Share on other sites More sharing options...
wrathican Posted June 28, 2007 Author Share Posted June 28, 2007 so i would set the limit with mysql? i was thinking of using a counter but i guess that would slow the website down once there are many entries in the news table. so all i do is just order it and limit the number of entries it takes. sorted. Thanks! Link to comment https://forums.phpfreaks.com/topic/57629-solved-php-news-section/#findComment-285287 Share on other sites More sharing options...
pocobueno1388 Posted June 28, 2007 Share Posted June 28, 2007 so i would set the limit with mysql? Yep, thats all it takes in your situation =] Don't forget to mark the topic as solved. Link to comment https://forums.phpfreaks.com/topic/57629-solved-php-news-section/#findComment-285290 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.