J-Buck Posted May 31, 2010 Share Posted May 31, 2010 Im Working on a calendar, but am having trouble adding Sunday-Saturday to the top row. Whenever i do it i get an error. Here is my code without doing it <title>Table</title> <?php echo "<table border='1'>"; $Number = 1; for ($Row = 0; $Row < 6; $Row++) {echo '<tr>'; for ($Column= 0; $Column < 7; $Column++) {echo "<td>$Number</td>";; $Number++; } echo '</tr>'; } echo "</table>"; ?> Link to comment https://forums.phpfreaks.com/topic/203440-php-calendar/ Share on other sites More sharing options...
kenrbnsn Posted May 31, 2010 Share Posted May 31, 2010 And the error is??? Link to comment https://forums.phpfreaks.com/topic/203440-php-calendar/#findComment-1065780 Share on other sites More sharing options...
J-Buck Posted May 31, 2010 Author Share Posted May 31, 2010 There error is when i try to add the days of the week. <title>Table</title> <?php echo "<table border='1'>"; $Number = 1; <tr> <td>Sunday</td> <td>Monday</td> <td>Tuesday</td> <td>Wednesday</td> <td>Thursday</td> <td>Friday</td> <td>Saturday</td> </tr> for ($Row = 0; $Row < 6; $Row++) {echo '<tr>'; for ($Column= 0; $Column < 7; $Column++) {echo "<td>$Number</td>";; $Number++; } echo '</tr>'; } echo "</table>"; ?> Link to comment https://forums.phpfreaks.com/topic/203440-php-calendar/#findComment-1065782 Share on other sites More sharing options...
kenrbnsn Posted May 31, 2010 Share Posted May 31, 2010 What is the error you're getting? Link to comment https://forums.phpfreaks.com/topic/203440-php-calendar/#findComment-1065783 Share on other sites More sharing options...
J-Buck Posted May 31, 2010 Author Share Posted May 31, 2010 parse error, unexpected '<' in Link to comment https://forums.phpfreaks.com/topic/203440-php-calendar/#findComment-1065785 Share on other sites More sharing options...
J-Buck Posted May 31, 2010 Author Share Posted May 31, 2010 cool got it working. i'll prolly have more questions in a bit <title>Table</title> <?php echo "<table border='1'>"; $Number = 1; '<tr>'; echo "<td>Sunday</td>"; echo "<td>Monday</td>"; echo "<td>Tuesday</td>"; echo "<td>Wednesday</td>"; echo "<td>Thursday</td>"; echo "<td>Friday</td>"; echo "<td>Saturday</td>"; '</tr>'; for ($Row = 0; $Row < 6; $Row++) {echo '<tr>'; for ($Column= 0; $Column < 7; $Column++) {echo "<td>$Number</td>";; $Number++; } echo '</tr>'; } echo "</table>"; ?> Link to comment https://forums.phpfreaks.com/topic/203440-php-calendar/#findComment-1065787 Share on other sites More sharing options...
J-Buck Posted May 31, 2010 Author Share Posted May 31, 2010 how do i get it to display the current month? Link to comment https://forums.phpfreaks.com/topic/203440-php-calendar/#findComment-1065793 Share on other sites More sharing options...
jskywalker Posted May 31, 2010 Share Posted May 31, 2010 echo $current_month; Before doing this, you should assign this variable with the value of the current month; How this can be done, is in the manual at : http://nl.php.net/manual/en/function.jdmonthname.php But i recommend taking a look at: http://nl.php.net/manual/en/function.date.php which gives a more generic approach $current_month = date('%F'); Link to comment https://forums.phpfreaks.com/topic/203440-php-calendar/#findComment-1065810 Share on other sites More sharing options...
J-Buck Posted May 31, 2010 Author Share Posted May 31, 2010 Thank you, i'll check that out Link to comment https://forums.phpfreaks.com/topic/203440-php-calendar/#findComment-1065815 Share on other sites More sharing options...
J-Buck Posted May 31, 2010 Author Share Posted May 31, 2010 Got the month displayed, but i want the $Month_Date to be on a row of its own and have the days of the week under that but everytime i try to do that it adds $Month_Date to the section that says Sunday-Saturday instead of above it by itself. <?php echo "<a href='http://table_cal.php/'>Today</a> is: "; echo(date("l\, F dS Y") . "<br /><br />"); echo "<table border='1'>"; $Number = 1; $Month_Date = date("F Y"); '<td>'; echo "<tr>$Month_Date</tr>"; '</td>'; '<tr>'; echo "<td>Sunday</td>"; echo "<td>Monday</td>"; echo "<td>Tuesday</td>"; echo "<td>Wednesday</td>"; echo "<td>Thursday</td>"; echo "<td>Friday</td>"; echo "<td>Saturday</td>"; '</tr>'; for ($Row = 0; $Row < 6; $Row++) {echo '<tr>'; for ($Column= 0; $Column < 7; $Column++) {echo "<td>$Number</td>";; $Number++; } echo '</tr>'; } echo "</table>"; ?> Link to comment https://forums.phpfreaks.com/topic/203440-php-calendar/#findComment-1065831 Share on other sites More sharing options...
jcbones Posted May 31, 2010 Share Posted May 31, 2010 I got the month and year on it's own row like you wanted. I also made some notations that should help you get it nailed down. Feel free to ask for more help if needed. <?php echo "<a href='http://table_cal.php/'>Today</a> is: "; echo(date("l\, F dS Y") . "<br /><br />"); echo "<table border='1'>"; $Number = 1; //Suggestion: seperate month and year for access to them later. $Month = date("F"); $Year = date('Y'); $Month_number = date('n'); //Edited the next line (JcBones) echo "<tr><td colspan=\"7\" align=\"center\">$Month $Year</td></tr>"; echo '<tr>'; echo "<td>Sunday</td>"; echo "<td>Monday</td>"; echo "<td>Tuesday</td>"; echo "<td>Wednesday</td>"; echo "<td>Thursday</td>"; echo "<td>Friday</td>"; echo "<td>Saturday</td>"; '</tr>'; //Suggestion: date('t') gets the days in the month. $days_in_month = date('t'); //Suggestion: Get the first day of the month. $first_day_of_month = date('l',mktime(0,0,0,$Month_number,1,$Year)); //You need to incorporate the above variables in order to get the //calendar to show the right dates on the right days. //IE. The first day of May was on a Saturday. for ($Row = 0; $Row < 6; $Row++) {echo '<tr>'; for ($Column= 0; $Column < 7; $Column++) {echo "<td>$Number</td>";; $Number++; } echo '</tr>'; } echo "</table>"; ?> Link to comment https://forums.phpfreaks.com/topic/203440-php-calendar/#findComment-1065855 Share on other sites More sharing options...
J-Buck Posted May 31, 2010 Author Share Posted May 31, 2010 Thank you very much. I'm incorporating the days in a month and day of month right now. Also any recommendations on a good xhtml/php book? I want to really get the hang of this so i can start making websites. Link to comment https://forums.phpfreaks.com/topic/203440-php-calendar/#findComment-1065865 Share on other sites More sharing options...
J-Buck Posted May 31, 2010 Author Share Posted May 31, 2010 Should i use the while loop for days in a month Link to comment https://forums.phpfreaks.com/topic/203440-php-calendar/#findComment-1065887 Share on other sites More sharing options...
J-Buck Posted May 31, 2010 Author Share Posted May 31, 2010 nvm. i used an if statement for ($Column= 0; $Column < 7; $Column++) { if ($Number <= $days_in_month) {echo "<td>$Number</td>";; $Number++; } } echo '</tr>'; Now i'm adding the starting day Link to comment https://forums.phpfreaks.com/topic/203440-php-calendar/#findComment-1065891 Share on other sites More sharing options...
J-Buck Posted May 31, 2010 Author Share Posted May 31, 2010 havin a bunch of trouble trying to figure out where to insert the line of code that will have the calendar start at the correct month. I cant seem to stop it from starting at the first cell, when it just needs to be cell pads until them month starts Link to comment https://forums.phpfreaks.com/topic/203440-php-calendar/#findComment-1065903 Share on other sites More sharing options...
jcbones Posted June 1, 2010 Share Posted June 1, 2010 This may help you with your project. Although, I don't suggest a copy/paste approach, rather a read/learn approach. Link to comment https://forums.phpfreaks.com/topic/203440-php-calendar/#findComment-1065936 Share on other sites More sharing options...
J-Buck Posted June 1, 2010 Author Share Posted June 1, 2010 Thank you! I knew i needed a switch just didn't know how to implement it Link to comment https://forums.phpfreaks.com/topic/203440-php-calendar/#findComment-1065944 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.