Welcome Guest, Not a member yet? Register   Sign In
Sql query with date where clause
#11

[eluser]CodeIgniteMe[/eluser]
[quote author="Todlerone" date="1300845195"]Great I got it to work using the model. I used this in my model
Code:
function stats_mth($mth){
     $query = $this->db->query("SELECT * FROM `demographics` WHERE MONTH(`demo_created_on`) = $mth");
     if($query->num_rows()>0){
    return $query->num_rows();
     }        
}
[/quote]
This method may not return any result if there are no (0) rows in the query. You can safely remove the "if" condition, because the
Code:
$query->num_rows();
will just simply return (int) 0 if there are no rows. So in your view, you may have:

New people in December: 0.
and I suggest including the year in your view:

New people in December 2010 : 0.

Just my suggestion.




Theme © iAndrew 2016 - Forum software by © MyBB