bigdaddysheikh
08-03-2007, 12:23 AM
Hey,
This is my first ever proper script. After 4 years of copying and pasting I am finally trying to learn how to do thing correctly. I read over 3 tutorials on how to make a calendar. The logic I did not understand due to it being complex. I am uncertain why they used arrays or classes but then again I do not know what they are.
I am just starting my path on this coding properly and getting my logic down. So any help or areas I need to improve let me know guys.
<?
//day of the month
$date = date("d");
$month = date("m");
$year = date("Y");
//getting the first day
$daysInMonth = date('t', mktime(0,0,0,$month,1,$year));
//numerical value of the first day
$firstDay = date("w", mktime(0,0,0,$month,1,$year));
//number of weeks in the month
$rows = ceil($daysInMonth/7);
$htmlValue = "<div id='calendar'>
<span><h2>August</h2></span>
<div id='cal_layout'>
<table>
<thead>
<tr>
<th>S</th>
<th>M</th>
<th>T</th>
<th>W</th>
<th>T</th>
<th>F</th>
<th>S</th>
</tr>
</thead>
<tbody>";
for ($i=1; $i<=$rows; $i++){
$htmlValue .= "<tr>";
for ($j=0; $j<=6; $j++){
//counting for the number of days
$counter++;
$days = $counter;
$days -= $firstDay;
if($days >= 1 && $days <= $daysInMonth) {
$htmlValue .= "<td><a href='' title='Sunday'>$days</a></td>";
}else{
$htmlValue .= "<td></td>";
}
}
$htmlValue .= "</tr>";
}
"</tbody></table></div></div>";
?>
This is my first ever proper script. After 4 years of copying and pasting I am finally trying to learn how to do thing correctly. I read over 3 tutorials on how to make a calendar. The logic I did not understand due to it being complex. I am uncertain why they used arrays or classes but then again I do not know what they are.
I am just starting my path on this coding properly and getting my logic down. So any help or areas I need to improve let me know guys.
<?
//day of the month
$date = date("d");
$month = date("m");
$year = date("Y");
//getting the first day
$daysInMonth = date('t', mktime(0,0,0,$month,1,$year));
//numerical value of the first day
$firstDay = date("w", mktime(0,0,0,$month,1,$year));
//number of weeks in the month
$rows = ceil($daysInMonth/7);
$htmlValue = "<div id='calendar'>
<span><h2>August</h2></span>
<div id='cal_layout'>
<table>
<thead>
<tr>
<th>S</th>
<th>M</th>
<th>T</th>
<th>W</th>
<th>T</th>
<th>F</th>
<th>S</th>
</tr>
</thead>
<tbody>";
for ($i=1; $i<=$rows; $i++){
$htmlValue .= "<tr>";
for ($j=0; $j<=6; $j++){
//counting for the number of days
$counter++;
$days = $counter;
$days -= $firstDay;
if($days >= 1 && $days <= $daysInMonth) {
$htmlValue .= "<td><a href='' title='Sunday'>$days</a></td>";
}else{
$htmlValue .= "<td></td>";
}
}
$htmlValue .= "</tr>";
}
"</tbody></table></div></div>";
?>