I'm trying to loop through every day in a month and get the number of results for each day in one month.
I've done the following;
<?php
include 'inclues/db.inc.php';
for($i = 2; $i < 30; $i++){
$date2 = $i-1;
$date1 = $i;
$q = mysql_query("SELECT * FROM `table` WHERE `date` < '2012-09-".$date1." 00:00:00' AND `date` > '2012-09-".$date2." 00:00:00'";
//$r = mysql_fetch_assoc($q);
echo mysql_num_rows($q)."<br />";
}
?>
It works if I just try to echo out dates 1 and 2 but not if I use the query.. I end up with a 500 internal server error when using the query.
Any ideas on how to resolve this? Is it generally bad practice to use a query within a loop?