-1

Am working on my new website which will be focused on sports betting. Users are able to post their bets and than they can be seen on their profile. I made section called LAST BETS on user profile which is showing last bets posted by this user .

Now I want to made another section that will sort bets by months. To better understand what I mean i will post 1 image .

https://i.stack.imgur.com/mAZdf.jpg

This is how mysql table looks like where matches are stored:

https://i.stack.imgur.com/SfpK4.jpg

Basicly what i need is to find in what month of what year user posted bets and sort em by month.

I am a novice in php and mysql , I try to learn from forums and youtube, so if anyone can help me with some suggestion it will be awsome :) Thanks

MHB2011
  • 453
  • 1
  • 7
  • 22

2 Answers2

1

You need to GROUP BY YEAR(date), MONTH(date) See MySQL Query GROUP BY day / month / year . If you can upload an example to sqlfiddle, I am happy to help further create your query.

Community
  • 1
  • 1
jkirchne
  • 121
  • 3
  • i have never before used sqlfiddle .. am trying to export my table there but am doing something wrong :/ Anyway here is matches table in sql format http://www.speedyshare.com/YUaZb/matches.sql .. Thanks for ur help – MHB2011 Apr 20 '14 at 13:18
  • Hey I just did this but had smoe problems with grouping. I just solve it and want to say that better option is to use: GROUP BY DATE_FORMAT(record_date, '%Y%m') . If anyone ever had same problem – MHB2011 Apr 20 '14 at 17:53
0

You can sort them like this.

CREATE VIEW marts AS
(SELECT * FROM yourTable WHERE DATE_FORMAT(date,'%M')='Marts')

Then you can make php run the queries from the links.

SELECT * FROM marts
el3ien
  • 5,362
  • 1
  • 17
  • 33