Reputation: 2961
My Goal is to spit out the data in my fields based on a date via a query. My table consists of 9 Fields, one of them being DATE.
DATE 5STAR 4STAR 3STAR 2STAR 1STAR TOTAL
2/9/2012 94 30 7 4 10 145
2/11/2012 95 31 7 4 10 147
2/12/2012 95 31 8 4 10 148
Here's the kicker. If there is NO DATE such as "2/10/2012" I want to spit out the data in php that is based off the most recent date, so I would spit out data for "2/9/2012" if they selected "2/10/2012".
Any suggestions for a query or do I have to upload all these dates to my database?
Upvotes: 0
Views: 159
Reputation: 207
SELECT * FROM table_name WHERE date <= "2012-02-10" ORDER BY date desc LIMIT 1
make sure your DATE column is a date field. And you're good to go!
Replace 2/10/2012 with whatever user inputs in PHP.
Upvotes: 2