2

Example my_table

ID | Name | Date
--------------------------
12 | John | 123456789
13 | Mike | 987654321
...
29 | Rick | 123498765
30 | Adam | 987651234

show output result like this

Month | Count
--------------------------
3 | 5 | 
6 | 8 | 

How can I do this with PHP?

1
  • You need to calculate the start and end of the month in epoch time, then use a BETWEEN type MySQL query. Commented Oct 11, 2017 at 6:28

2 Answers 2

5

You can do this using MySQL Query as below.

SELECT MONTH(FROM_UNIXTIME(`Date`)) `Month`
    ,COUNT(ID)
FROM my_table
GROUP BY `Month`;
Sign up to request clarification or add additional context in comments.

Comments

2

Since post tagged

This is codeigniter way:

$query = $this->db->select("month(from_unixtime(`Date`)) as `month`, count(1) as `count`",FALSE)
                  ->group_by("month");
                  ->get("your_table");

1 Comment

In this answer can we add 1 column called "names" with adding comma separate names, for example, month value is 3 then cell show 3 names in comma separares. Can you able to share the lines of code ? so its help to getting name list in single sql query. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.