Welcome to Dream.In.Code
Getting Help is Easy!

Join 109,536 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,251 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



Getting all dates after today from table.

 
Reply to this topicStart new topic

Getting all dates after today from table.

jeffmc21
post 22 Jul, 2008 - 08:05 PM
Post #1


New D.I.C Head

*
Joined: 27 Nov, 2007
Posts: 40


My Contributions


I have a table with date field 'event_date' and I want to get all records where 'event_date' >= today's date. Basically, I want to retrieve all upcoming events (acutally next 4, but let's shoot for all of them for right now).

Any advice on the SQL syntax to use to accomplish this?
User is offlineProfile CardPM

Go to the top of the page


mocker
post 23 Jul, 2008 - 11:59 AM
Post #2


D.I.C Head

**
Joined: 14 Oct, 2007
Posts: 177



Thanked 6 times
My Contributions


You basically answered your question..

SELECT * FROM YOUR_TABLE WHERE event_date >= date(now())

If you want to limit it to the next 4 events add
ORDER BY event_date LIMIT 4
User is offlineProfile CardPM

Go to the top of the page

jeffmc21
post 23 Jul, 2008 - 12:58 PM
Post #3


New D.I.C Head

*
Joined: 27 Nov, 2007
Posts: 40


My Contributions


QUOTE(mocker @ 23 Jul, 2008 - 11:59 AM) *

You basically answered your question..

SELECT * FROM YOUR_TABLE WHERE event_date >= date(now())

If you want to limit it to the next 4 events add
ORDER BY event_date LIMIT 4



Thanks. That works perfectly. However, I'm now stuck again...

It obviously returns 4 rows from the table, each of the rows containing an event_id, event_date, and event_name field.

How do I echo or print the results properly? I'm wanting a list, similar to this:

<li>event_date1 - event_name1</li>
<li>event_date2 - event_name2</li>....etc.

Any advice?
User is offlineProfile CardPM

Go to the top of the page

jeffmc21
post 23 Jul, 2008 - 07:06 PM
Post #4


New D.I.C Head

*
Joined: 27 Nov, 2007
Posts: 40


My Contributions


I actually ended up using this:

CODE

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo '<li>'. $row["event_date"] .' - '. $row["event_name"].'</li>';
}


Any idea on how to re-format the date field? I've been working on it for hours, and I think I'm dancing all around the answer, but can't seem to get the right one.

It comes from the Database as YYYY-MM-DD. Preferably, I'd like to have it as Month, DD. But I'd settle for MM-DD or MM/DD.
User is offlineProfile CardPM

Go to the top of the page

jeffmc21
post 24 Jul, 2008 - 07:00 PM
Post #5


New D.I.C Head

*
Joined: 27 Nov, 2007
Posts: 40


My Contributions


Figuring this out slowly!

My SQL call looks like this currently:

SELECT * FROM `tbl_eventsName` WHERE `event_date` >= CURDATE() ORDER BY event_date LIMIT 4


Where would I add the Date_format('event_date', '%a %b %e') adjustment? I looked at the manual and several online examples, and I understand the format I need for the date and what it's doing, but where would I place it in my call?
User is offlineProfile CardPM

Go to the top of the page

Trogdor
post 28 Jul, 2008 - 05:29 AM
Post #6


D.I.C Regular

Group Icon
Joined: 6 Oct, 2006
Posts: 451



Thanked 2 times

Dream Kudos: 125
My Contributions


instead of select * , you should specify the fieldnames that you want to select.
One of those should be Date_format('event_date', '%a %b %e')
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 9/7/08 09:48PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month