bobby317 Posted April 30, 2010 Share Posted April 30, 2010 Hello I am new to php and have taken 1 beginner class. I am creating my first php project so that I can improve my knowledge. It is a basic calendar that I will slowly one day make into an event calendar with a database. What I am trying to do now is style the current date (like highlight the background or bold the date). Any advise would be great. Also if you could explain it as well in your post would be great. Thanks Here is my code as of now: <?php $date =time (); //Determans the time //Formate date $day = date('d', $date); $month = date('m', $date); $year = date('Y', $date); //Generate the first day of the month $first_day = mktime(0,0,0,$month, 1, $year); //Get month name $title = date('F', $first_day); //Find day of the week the first day falls on $day_of_week = date('D', $first_day); //Assign blank varable for blank days at beginnng of month Switch($day_of_week){ case "Sun": $blank = 0; break; case "Mon": $blank = 1; break; case "Tue": $blank = 2; break; case "Wed": $blank = 3; break; case "Thu": $blank = 4; break; case "Fri": $blank = 5; break; case "Sat": $blank = 6; break; } //Find out how many days in month $days_in_month = cal_days_in_month(0, $month, $year); //Style the table echo "<style type=text/css> body { text-align: center; } table { width: 500px; height: 500px; border-width: 6px; border-style: solid; border-color: #000000; } th, td { width: 62px; height: 62px; border-width: 1px; border-style: solid; border-color: #000000; text-align: center; } </style>"; //Open body html tag echo"<body>"; //Create Table echo "<table>"; echo "<tr><th colspan=60> $title $year </th></tr>"; echo "<tr><td>Sunday</td><td>Monday</td><td>Tuesday</td><td>Wedsday</td><td>Thursday</td><td>Friday</td><td>Saturday</td>"; //count days in week $day_count =1; //Echo table row echo "<tr>"; //Add blank days to beginning of calander while ( $blank > 0) { echo "<td> </td>"; $blank = $blank-1; $day_count++; } //Set day Number to 1 $day_num = 1; //count day of the month //increase day_num //increase day_count while ( $day_num <= $days_in_month ) { echo "<td> $day_num </td>"; $day_num++; $day_count++; //create a new row if ($day_count > 7) { echo "</tr><tr>"; $day_count = 1; } } //Add blank days to end of calander while ( $day_count >1 && $day_count <=7 ) { echo "<td> </td>"; $day_count++; } //Close table echo "</tr></table>"; //Close body tag echo "</body>"; ?> Quote Link to comment Share on other sites More sharing options...
MatthewJ Posted April 30, 2010 Share Posted April 30, 2010 //count day of the month //increase day_num //increase day_count while ( $day_num <= $days_in_month ) { if(date('d') != $day_num) { echo "<td> $day_num </td>"; $day_num++; $day_count++; } else { echo "<td> <strong>$day_num</strong> </td>"; $day_num++; $day_count++; } You just needed to add an if around this part of the code to check if the $day_num value is equal to today. Quote Link to comment Share on other sites More sharing options...
bobby317 Posted April 30, 2010 Author Share Posted April 30, 2010 Thank you very much. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.