CodeIgniter Forums
How get current month records in Mysql? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: How get current month records in Mysql? (/showthread.php?tid=81853)



How get current month records in Mysql? - omid_student - 05-10-2022

I have many records for all days.
Some days have no data example 2020-12-10 or others.
When I use the below query:
SELECT COUNT(*),DATE(date_register) FROM tbl_order WHERE MONTH(NOW()) = 1
The query return only rows that exist for that date
How do I can set 0 for dates that not have any records
Thanks


RE: How get current month records in Mysql? - php_rocs - 05-10-2022

@omid_student ,

Right off the top of my head......try this: SELECT Count(*), DATE(date_register) FROM tbl_order Order By date_register. For me to dive in a little more deeper I would need more information about the table. Maybe you could use something like ... http://sqlfiddle.com/


RE: How get current month records in Mysql? - demyr - 05-10-2022

What about CI Model way of counting? The same result? Documentation