Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

MySQL + PHP (grouping by date)

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

MySQL + PHP (grouping by date)

Postby ethar » Tue Jun 04, 2013 4:02 pm

I'm trying to output a list of different itmes grouped by the date they were stored in the database (unix timestamp).

I'd need help with both MySQL (query) and PHP (output).

MySQL table

id | subject | time
1 | test1 | 1280278800
2 | test2 | 1280278800
3 | test3 | 1280365200
4 | test4 | 1280451600
5 | test5 | 1280451600

OUTPUT

Today
test5
test4

Yesterday
test3

July 28
test2
test1

I'd appreciate any help on this. Thanks!
ethar
New php-forum User
New php-forum User
 
Posts: 1
Joined: Tue Jun 04, 2013 3:58 pm

Re: MySQL + PHP (grouping by date)

Postby pbs » Tue Jun 04, 2013 8:52 pm

try this query

Code: Select all
SELECT id,subject,time FROM TABLE GROUP BY time
pbs
New php-forum User
New php-forum User
 
Posts: 39
Joined: Sat May 11, 2013 1:40 am
Location: Nashik, India

Re: MySQL + PHP (grouping by date)

Postby johnmacd » Thu Jun 13, 2013 10:35 pm

Use group by clause for time in mysql query.
johnmacd
New php-forum User
New php-forum User
 
Posts: 19
Joined: Wed Jun 12, 2013 9:30 pm


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 4 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.