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? Quote Link to comment 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. Quote Link to comment 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.. Quote Link to comment 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! Quote Link to comment 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. Quote Link to comment 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.