I'm trying to retrieve the distinct dates from a table and throw the results into an array. The table contains about 10 records with a log_date of 11/26/2007 and 8 records with a log date of 11/27/2007.
With the SQL statement below, I should be getting two records but the array only prints one.
$query = "SELECT log_date FROM food_log GROUP BY log_date";
$result = mysql_query($query, $conn) or die('Error, query failed');
$row = mysql_fetch_array($result);
while($row = mysql_fetch_array($result)) {
echo $row['log_date'] . '<BR>';
}
This should return two rows. The SQL statement works when I run it outside of PHP but the resulting array only contains one record. It should contain two.
I have also tried using print_r () and that only shows me one element as well.
Is there a problem with using a GROUP BY clause in my SQL? Should I be using something different than mysql_fetch_array?
Thanks in advance...