title: Count How many Data in a month based on Criteria
body: <p>I have 2 tables, <code>master_kategori_project</code> which is contain category of projects and <code>project</code> which is contains how many project in a specific month in a specific year. below is my <code>master_kategori_project</code> table.</p>
  
  <pre><code>id| category_project | description |
  1 | Category 1       | descrip 1   |
  2 | Category 2       | descrip 2   |
  3 | Category 3       | descrip 3   |
  </code></pre>
  
  <p>and my <code>project</code> table look something like this</p>
  
  <pre><code>id| id_category_project | name_project | start_date |
  1 | 1                   | Project 1    | 27-01-2017 |
  2 | 2                   | Project 2    | 29-02-2017 |
  </code></pre>
  
  <p>i want to make a table that contain chart like this, u can see from the table on <strong>january</strong> i have 3 projects of kategori 1, 5 projects of kategori 2, 7 projects of kategori 3 and so on</p>
  
  <p>how can i write an query that have something like this? the chart is automatically build by the table itself.</p>
  
  <p><a href="https://i.stack.imgur.com/kUpI7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kUpI7.png" alt="enter image description here"></a></p>
  
  <p>this is my model and i believe i did it wrong, because i can't put the data into the correct month</p>
  
  <pre><code>public function get_kategori_totals($mnth, $year=null)
  {   
      $yr=date('Y');
      $select = "
          SELECT COUNT(category_project),start_date,category_project
          FROM
              project
          LEFT JOIN
              master_kategori_project
          ON
              project.id_category_project=master_kategori_project.id
          WHERE 
              MONTH(start_date)='$mnth'".
              (($year == null)?" AND YEAR(start_date)='$yr' GROUP BY category_project":"AND YEAR(stat_date)='$year' GROUP BY category_project");
      return $this-&gt;db-&gt;query($select);
  }
  </code></pre>