Welcome to WebmasterWorld Guest from 54.159.242.217

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

IF statement.please help

     
9:15 am on Mar 4, 2011 (gmt 0)

Junior Member

5+ Year Member

joined:June 20, 2007
posts:62
votes: 0


I'm not sure if this post should go in this forum or the database forum.

I have an events table that include start_date and end_date columns. Both datatypes are DATE and stored in 2011-01-01 format.

I've managed to explode the data and get day, month, year values to use in my html table.

+------------+--------------+----------------------+
| start | end | name |
+------------+--------------+----------------------+
| feb 17 | feb 23 | event 1 |
| feb 24 | feb 27 | event 2 |
| feb 28 | mar 03 | event 3 |
| mar 04 | mar 08 | event 4 |
| mar 09 | mar 13 | event 5 |
+------------+--------------+----------------------+

I'm able to display the data from the table but its just a continual list. I'd like to insert a row (spanning all columns) that displays the month name (whenever the start date is in that particular month).

I've had a look round the net and the forums but can't seem to find a solution. Any advice guys and gals? I'm sure its pretty simple but I just can't seem to fathom it out.

Thanks
1:37 pm on Mar 4, 2011 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member 10+ Year Member

joined:Aug 1, 2003
posts:815
votes: 0


This is best done in your PHP code that displays the page. It's purely about presentation, so it doesn't belong in the database logic.

Something like this would work:

1 Create varaibles for curent month heading and set to empty string.

2 For each row in the database.

3 Get the row data.

4 If the month selected from the row differs from the current month heading, generate a new month heading, and set the current month heading to the new value.

5 Output the row data.

6 Proceed to next row in database.
5:00 pm on Mar 4, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 28, 2004
posts:7999
votes: 0


That's how I'd do it, see my post here [webmasterworld.com] for an example.
4:33 pm on Mar 5, 2011 (gmt 0)

Junior Member

5+ Year Member

joined:June 20, 2007
posts:62
votes: 0


Thanks so much guys. This is perfect.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members