views:

67

answers:

1

Hello! I'm curious if anyone could possibly help me, because I can't find anything exactly related to it anywhere, and it's driving me nuts.

I'd like to have a dropdown list on a page, that will give the visitor the option to sort all entries by year. I have entries from i.e. 2001, 2005, 2009, 2010. The years should be displayed in the dropdown, so the visitor can easily just select all entries dated 2001 if they want. The year for each entry is located in the one database table I have.

In other words, I simply want a "sort by" dropdown that you can see on pretty much any shopping site nowadays. But with set years.

Thanks in advance for any replies!

+1  A: 

Well, you create a dropdown, make a query, and use the ORDER BY syntax to order it by a certain field.

So, to sort it by year (Oldest to Newest):

SELECT * FROM table ORDER BY Year ASC

Newest to Oldest

SELECT * FROM table ORDER BY Year DESC

Perhaps you mispoke, and meant to say filter by the year. In that case you would use the WHERE clause:

SELECT * FROM table WHERE Year="2010"

This would make it so that only posts with the year 2010 are included.

Chacha102
Ah yeah, maybe you'd say filter. The only way I seem to get this to work is if I make a separate PHP page with the query and link the dropdown link to the new page. And that's not really practical if i ever want to edit the page. I'm quite the beginner at this, so this is very puzzling to me, and I'm not sure if it's even do-able to keep it all on one page...
Lin