Reputation: 593
Here is what I want to do: I want to have a script that grabs all of the images a user ever shared on my site, and display them in groups based on the month/date when they shared it.
Here is my table structure:
| user_id | post_date | story | image |
|-------------------------------------|
| 14 | mar 2012 | BLOB | a.jpg |
| 14 | apr 2012 | BLOB | b.jpg |
| 14 | feb 2012 | BLOB | c.jpg |
| 14 | mar 2012 | BLOB | d.jpg |
|_____________________________________|
So, I want the information retrieved based upon the user's id, then displayed in groups based upon date. I am clueless as where to start. The group names are the name of the month, so do I have to do a query to figure out how many different months a user shared a post in? And then how do I group the data? I am not expecting someone to code everything for me. I just am unsure of how to start. Thanks.
Upvotes: 1
Views: 52
Reputation: 6003
You can order them by post_date
select fields from mytable order by post_date
but you can't really have subgroups as below:
select fields from mytable group by year(post_date), month(post_date)
Upvotes: 1
Reputation: 2109
Start with the query, it might solve all of your problems. If you want a good answer, please include an example of the result you want. Something like
Select image, post_date
Where user_id = @userId
Order By post_date Desc
Then read through the results, and when the month/year/whatever changes in the date returned, create a new "group".
Upvotes: 1