jardane
jardane

Reputation: 471

Pull three upcoming events from MySQL database

I have a database of events that are used to fill a PHP calender. I want to also have a page that lists three upcoming events in date order when ever the page loads. The records have a separate field for day, month and year. The issue i run in to is getting records that accrue after the current date.

Upvotes: 0

Views: 868

Answers (2)

Tony Hopkinson
Tony Hopkinson

Reputation: 20320

You are going to have to build a date from your three fields to test against current date, or split current date into year, month, day and test all three against data in your table.

Got to say, not a brill decision on someones part to split date like that.

Need table structure before we can properly help query wise.

Upvotes: 1

Yasen Zhelev
Yasen Zhelev

Reputation: 4045

Table structure will be good to have but I will guess the query that you need. Use that as a point to start from.

SELECT * FROM events WHERE CONCAT(year,'-',month,'-',date) > DATE_FORMAT(NOW(),'%Y-%m-%d')
ORDER BY year DESC, month DESC, date DESC LIMIT 3;

Upvotes: 1

Related Questions