PHP Get count

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

durgaprasadcs
New php-forum User
New php-forum User
Posts: 1
Joined: Thu Mar 27, 2014 11:26 am

PHP Get count

Postby durgaprasadcs » Thu Mar 27, 2014 11:37 am

Hi all,

I have records in my sql database which contains fields like ID, Name, Date
I need Name Count grouped by Month using date field.

Example :
ID | Name | Date (mm/dd/yyyy)
-----------------------
1 John 01/01/2013
2 David 01/20/2013
3 Harry 02/10/2013


So when i get the count based on the above data, if should be like follow

January - 2
February - 1


That is John and David falling in January Month
Harry is falling in February Month

How can i acheive this. Its like kind of excel pivot table.

raphael75
New php-forum User
New php-forum User
Posts: 20
Joined: Fri Apr 06, 2012 9:54 pm

Re: PHP Get count

Postby raphael75 » Mon Mar 31, 2014 10:59 am

something like:

Code: Select all

select
  count(id) as 'total',
  monthname(date) as 'month'
from
  tablename
group by
  month
order by
  total desc


Return to “PHP coding => General”

Who is online

Users browsing this forum: Google [Bot] and 5 guests