Forum Moderators: coopster

Message Too Old, No Replies

listing news by date, including image for each year

listing news by date, including image for each year

         

drooh

2:33 am on Feb 21, 2008 (gmt 0)

10+ Year Member



All of the news entries are stored in a mysql database with title and date.

On the page I would like to loop through and show an image for each year and under that image have all the news for that year. The problem I am having is that the image repeats itself for each entry. I would like the image to show up just one time and then all the news for that year under it. And then continue on to the next year and so forth.

Is there a way to write this in one statement instead of several? what logic should I use in this approach?

phparion

5:54 am on Feb 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



if you have stored the date in your table for each record then yes it is possible with single mysql query by using date functions. you can use PHP too by checking the date of the record.

I will recommend you to post your code and mysql query you are using that will give me a more clear idea of your current logic and how we can improve on your current code.

drooh

7:28 am on Feb 21, 2008 (gmt 0)

10+ Year Member



here is the basic logic

check to see all years of items in db
they are 2008 2007 2006 2005 2004
then echo img src graphic2008.jpg and then echo all entries for that year, continue on and echo graphic2007.jpg and all entires for that year.

I am wondering if I should use a for loop? or a foreach?
[w3schools.com...]