Welcome Doug! I ran a modified version of your SQL locally and I'm getting results even for those NULL dates. First things first - to real-time convert a null into some other value ("convert null to 0") you need to use the MySQL statement IF, if you know anything of Oracle, it's a lot like the DECODE
command. A NULL value automatically evaluates to false, so you can simply write:
SELECT IF(date_created,date_created,0) FROM sometable
Of course... 0 isn't anymore a date then NULL is. I found the DAYNAME
function simply passes on NULL dates for you to deal with:
SELECT DAYNAME(date_created) day,COUNT(*) my_count
FROM sometable
WHERE date_created IS NULL OR
(date_created>='2010-10-20 21:02:38' AND date_created <= '2010-10-27 21:02:38')
GROUP BY DAY(date_created)
What I'm getting out of that (with an example data set) is 8 values of day
: 7 days of the week + NULL (with a count). Which kinda makes sense... you can't convert an unknown date into a day of the week.
It could have been your errant @
signs in your SQL, unless I'm misunderstanding your purpose.
UPDATE
Based on your last comment, you need to take over processing in PHP. Build the days array before hand, then add the MySQL data to your existing array so that all the days are there (and in order).
Source: day-counting in PHP
//You may not even need "date_created IS NULL OR" in the where statement
$sql="SELECT DAYNAME(date_created) day,COUNT(*) my_count
FROM sometable
WHERE date_created IS NULL OR
(date_created>='2010-10-20 21:02:38'
AND date_created <= '2010-10-27 21:02:38')
GROUP BY DAY(date_created)";
//We're assuming you've setup a MySQL connection in $conn
$result = @mysql_query($sql, $conn) or die(mysql_error());
//Starting data - Zero for every day
$days=array("Sunday"=>0,"Monday"=>0,"Tuesday"=>0,"Wednesday"=>0,
"Thursday"=>0,"Friday"=>0,"Saturday"=>0);
while($row = mysql_fetch_array($result)) {
$days[$row["day"]]+=$row["my_count"];
}
mysql_free_result($result);
//Preview the output
print_r($days);