skygal
09-14-2008, 02:40 PM
Hello - I'm having trouble getting my nested tables to show correctly. Please ignore the php code and look at the table code... It displays the inner table after the outer table, instead of within it. I've even printed it out and used colored pencils to try to find the missing closing statement! I'm just not finding it. Do you see anything?
A view of how it looks currently (http://webdev4.matcmadison.edu/mbtest/lgr/a3/a3.php)
(Please excuse all the odd border colors - I'm using that to test my table issue and my border issue.)
Thanks for your help... the code is below
<?php
$year = date("Y"); // current year
if (isset($_GET['month']))
$month = $_GET['month'];
if (isset($_GET['year']))
$year = $_GET['year'];
else
$month = date("n"); // 9 for September
print ("<html>\n");
print ("<head>\n");
print ("<title>3</title>\n");
print ("</head>\n");
print ("<body>\n");
// Output to HTML table with a form for entering the month and year and a submit button
// outer table
print ("<table style='border:3px solid red' width='520' bgcolor='lightgrey' cellspacing='0' align='center'>\n");
// ***** tr and td of outer table
print ("<tr><td>\n");
print ("<tr align='center'>\r\n");
// print form
print ("<td colspan='7'>\n");
print("<form action='{$_SERVER['SCRIPT_NAME']}'" . "method='get'>\n");
// Ask for the year
print("<b>Year:</b> " .
"<input type='text' style='width:50px' name='year' " .
"value='$year'>\n" .
" \n");
// Ask for the month
print("<b>Month:</b> " .
"<select name='month'>" .
"<option value='1'>January</option>" .
"<option value='2'>February</option>" .
"<option value='3'>March</option>" .
"<option value='4'>April</option>" .
"<option value='5'>May</option>" .
"<option value='6'>June</option>" .
"<option value='7'>July</option>" .
"<option value='8'>August</option>" .
"<option value='9' selected='selected'>September</option>" .
"<option value='10'>October</option>" .
"<option value='11'>November</option>" .
"<option value='12'>December</option>" .
"</select>\n" .
" \n");
// Show submit button
print("<input type='submit' value='New Calendar'>\n");
print("</form>\n");
print("</td>\n");
print ("</tr>\n");
// Convert a month number to its name by getting a time stamp for that month
// (any day, any year) and then using date() against that timestamp with the
// right mnemonic:
$ts = mktime(0, 0, 0, $month, 15, 2008);
$monthName = date("F", $ts); // "January", "February", ...
print ("<tr>\n"); // Month and year row
print ("<th colspan='7'><h2>$monthName $year</h2></th>\n");
print ("</tr>\r\n");
// inner table
print ("<table style='border:1px solid blue' width='490' cellspacing='0' align='center'>\n");
print ("<tr>\r\n"); // day names
print ("<td width='50' align='center'>Sunday</td>\n");
print ("<td width='50' align='center'>Monday</td>\n");
print ("<td width='50' align='center'>Tuesday</td>\n");
print ("<td width='50' align='center'>Wednesday</td>\n");
print ("<td width='50' align='center'>Thursday</td>\n");
print ("<td width='50' align='center'>Friday</td>\n");
print ("<td width='50' align='center'>Saturday</td>\n");
print ("</tr>\r\n");
print "<tr>\n";
$date = mktime(0, 0, 0, $month, 1, $year);
// calculate number of days in a month
$daysInMonth = date("t", $date);
// calculate position of the first day in the calendar (sunday = 1st)
$firstDay = date("w", $date);
$rows = 1;
// blank tds before first day
for($blanktd = 1; $blanktd <= $firstDay; $blanktd++)
{
print "<td style='border:1px solid green'></td>";
}
for($day = 1; $day <= $daysInMonth; $day++)
{
if( ($day + $firstDay - 1) % 7 == 0 && $day != 1)
{
print "</tr>\n\t<tr>";
$rows++;
}
print "<td height='60' vAlign=top align=right width='14%' style='border:1px solid black' align='center'>" . $day . "</td>";
}
print "</tr>\n";
print ("</table>\n"); // end the inner table
print("<tr><td style='border:3px solid green'> </td></tr>\n"); // space
print ("</td></tr>\n"); // end the outer td and tr
print ("</table>\n"); // end the outer table
print ("</body>\r\n");
print ("</html>\r\n");
?>
A view of how it looks currently (http://webdev4.matcmadison.edu/mbtest/lgr/a3/a3.php)
(Please excuse all the odd border colors - I'm using that to test my table issue and my border issue.)
Thanks for your help... the code is below
<?php
$year = date("Y"); // current year
if (isset($_GET['month']))
$month = $_GET['month'];
if (isset($_GET['year']))
$year = $_GET['year'];
else
$month = date("n"); // 9 for September
print ("<html>\n");
print ("<head>\n");
print ("<title>3</title>\n");
print ("</head>\n");
print ("<body>\n");
// Output to HTML table with a form for entering the month and year and a submit button
// outer table
print ("<table style='border:3px solid red' width='520' bgcolor='lightgrey' cellspacing='0' align='center'>\n");
// ***** tr and td of outer table
print ("<tr><td>\n");
print ("<tr align='center'>\r\n");
// print form
print ("<td colspan='7'>\n");
print("<form action='{$_SERVER['SCRIPT_NAME']}'" . "method='get'>\n");
// Ask for the year
print("<b>Year:</b> " .
"<input type='text' style='width:50px' name='year' " .
"value='$year'>\n" .
" \n");
// Ask for the month
print("<b>Month:</b> " .
"<select name='month'>" .
"<option value='1'>January</option>" .
"<option value='2'>February</option>" .
"<option value='3'>March</option>" .
"<option value='4'>April</option>" .
"<option value='5'>May</option>" .
"<option value='6'>June</option>" .
"<option value='7'>July</option>" .
"<option value='8'>August</option>" .
"<option value='9' selected='selected'>September</option>" .
"<option value='10'>October</option>" .
"<option value='11'>November</option>" .
"<option value='12'>December</option>" .
"</select>\n" .
" \n");
// Show submit button
print("<input type='submit' value='New Calendar'>\n");
print("</form>\n");
print("</td>\n");
print ("</tr>\n");
// Convert a month number to its name by getting a time stamp for that month
// (any day, any year) and then using date() against that timestamp with the
// right mnemonic:
$ts = mktime(0, 0, 0, $month, 15, 2008);
$monthName = date("F", $ts); // "January", "February", ...
print ("<tr>\n"); // Month and year row
print ("<th colspan='7'><h2>$monthName $year</h2></th>\n");
print ("</tr>\r\n");
// inner table
print ("<table style='border:1px solid blue' width='490' cellspacing='0' align='center'>\n");
print ("<tr>\r\n"); // day names
print ("<td width='50' align='center'>Sunday</td>\n");
print ("<td width='50' align='center'>Monday</td>\n");
print ("<td width='50' align='center'>Tuesday</td>\n");
print ("<td width='50' align='center'>Wednesday</td>\n");
print ("<td width='50' align='center'>Thursday</td>\n");
print ("<td width='50' align='center'>Friday</td>\n");
print ("<td width='50' align='center'>Saturday</td>\n");
print ("</tr>\r\n");
print "<tr>\n";
$date = mktime(0, 0, 0, $month, 1, $year);
// calculate number of days in a month
$daysInMonth = date("t", $date);
// calculate position of the first day in the calendar (sunday = 1st)
$firstDay = date("w", $date);
$rows = 1;
// blank tds before first day
for($blanktd = 1; $blanktd <= $firstDay; $blanktd++)
{
print "<td style='border:1px solid green'></td>";
}
for($day = 1; $day <= $daysInMonth; $day++)
{
if( ($day + $firstDay - 1) % 7 == 0 && $day != 1)
{
print "</tr>\n\t<tr>";
$rows++;
}
print "<td height='60' vAlign=top align=right width='14%' style='border:1px solid black' align='center'>" . $day . "</td>";
}
print "</tr>\n";
print ("</table>\n"); // end the inner table
print("<tr><td style='border:3px solid green'> </td></tr>\n"); // space
print ("</td></tr>\n"); // end the outer td and tr
print ("</table>\n"); // end the outer table
print ("</body>\r\n");
print ("</html>\r\n");
?>