Forum Moderators: coopster

Message Too Old, No Replies

Calling Items Excluding the Most Recent from Database

Does such a command exist?

         

galileo5

1:17 am on Oct 27, 2006 (gmt 0)

10+ Year Member



Good evening.

Forgive me if I don't explain this clearly, but I'll try:

Is there a command to get results from a database that would display x amount of items, except the most recent?

For example, let's say I have 5 items in my database. Item 1 is the oldest, 5 is the newest. I want a certain area of my page to display items 4, 3, 2, and 1. Item 5 (the most recent one) is to go to another area of the page. As I input a new item (6, let's say), item 5 would join the other four.

If there is no way of doing that, here is my back-up plan I would hope you would be able to answer: I want the most recent item (item 5) to display more than just the title of the newsitem. The older ones (4, 3, 2, and 1) to display only the titles, so the visitors would click on the titles to read the article.

I hope this makes sense.

Thank you for your help

brevetoxin

1:51 am on Oct 27, 2006 (gmt 0)

10+ Year Member



One way to do it would be to simply add a field in the database table that is a time stamp for the addition of the records. When you retrieve records to display, you can then simply sort your query by time from newest to oldest, displaying the first result as you wish, then displaying the rest of the results in the other way.

eelixduppy

1:54 am on Oct 27, 2006 (gmt 0)



What you want to achieve can all be accomplished through the query. Something like this should do the trick:


$query = "SELECT * FROM table ORDER BY date_col ASC LIMIT 1,5";

Good luck!

galileo5

11:03 pm on Oct 28, 2006 (gmt 0)

10+ Year Member



Thank you both for your assistance.

eelixduppy, I went ahead with your advice, and it was exactly what I was looking for.

Thank you!