I have a database with a calendar table (each row represents one day) with 4 years of rows (2012, 2013, 2014, 2015). I use the column name calyear for the year.
I use the following code to find values for distinct years then display it:
$year = mysql_query("SELECT DISTINCT calyear FROM calendar");
while($yeararray = mysql_fetch_array($year))
{
echo($yeararray['calyear']."<br />");
}
The problem is it only displays the years 2013, 2014, 2015 even though when I use
echo(mysql_num_rows($year);
it displays the value 4 which I take to mean all 4 years are there. I'm not quite sure where I'm going wrong with this.
*EDIT*
Thanks for your suggestions but I found the problem and it was my own stupidity.
I had the $year query at the top of the page and the While loop later on (where I needed it). I'd earlier put $yeararray = mysql_fetch_array($year) directly underneath the $year so I had it twice on the page, and when I removed the redundant one at the top the code worked fine.
Thanks and sorry!
nullin the fourth row? it's the only thing I can think of given your description.