"; echo "<< $title $year >>"; echo "SMTWTFS"; //This counts the days in the week, up to 7 $day_count = 1; echo ""; //first we take care of those blank days while ( $blank > 0 ) { echo " "; $blank = $blank-1; $day_count++; } //sets the first day of the month to 1 $day_num = 1; //count up the days, untill we've done all of them in the month while ( $day_num <= $days_in_month ) { // Query DB and Match Day, Month, Year - make bg color change and make it a link. if( ($start_date_d == $day_num) && ($month == date("m")) && ($year == date("Y")) ){ echo " $day_num "; } elseif ( ($day_num == date("d")) && ($month == date("m")) && ($year == date("Y")) ){ echo " $day_num "; } else { echo " $day_num "; } $day_num++; $day_count++; //Make sure we start a new row every week if ($day_count > 7) { echo ""; $day_count = 1; } } //Finaly we finish out the table with some blanks if needed while ( $day_count >1 && $day_count <=7 ) { echo " "; $day_count++; } echo ""; ?>