xiaoxin22 Posted June 25, 2010 Share Posted June 25, 2010 need help on this.. got these codes from the net but there is some problem, all the months is ok except for august.. can someone help me on this..? I've been researching for a while but still can't solve it.. can someone please help me with this.. Thanks. function showCalendar(){ // Get key day informations. // We need the first and last day of the month and the actual day $today = getdate(); $firstDay = getdate(mktime(0,0,0,$month,1,$today['year'])); $lastDay = getdate(mktime(0,0,0,$month+1,0,$today['year'])); echo '<h2>' . $today['year'] . '</h2>'; // Create a table with the necessary header informations echo '<table id=form_part>'; echo ' <tr class=table_header><td style="border-right-color:#515151" colspan="7">' . $today['month'] . '</td>' . '</tr>'; echo '<tr class=table_header2>'; echo ' <td><strong>Monday</strong></td><td><strong>Tuesday</strong></td><td><strong>Wednesday</strong></td><td><strong>Thursday</strong></td>'; echo ' <td><strong>Friday</strong></td><td><strong>Saturday</strong></td><td><strong>Sunday</strong></td></tr>'; // Display the first calendar row with correct positioning echo '<tr>'; for($i=1;$i<$firstDay['wday'];$i++){ echo '<td> </td>'; } $actday = 0; for($i=$firstDay['wday'];$i<=7;$i++){ $actday++; load_events($actday, $month); } echo '</tr>'; //Get how many complete weeks are in the actual month $fullWeeks = floor(($lastDay['mday']-$actday)/7); for ($i=0;$i<$fullWeeks;$i++){ echo '<tr>'; for ($j=0;$j<7;$j++){ $actday++; load_events($actday, $month); } echo '</tr>'; } //Now display the rest of the month if ($actday < $lastDay['mday']){ echo '<tr>'; for ($i=0; $i<7;$i++){ $actday++; if ($actday <= $lastDay['mday']){ load_events($actday, $month); }//if else { echo '<td> </td>'; }//else }//for echo '</tr>'; }//ifelse echo '</table>'; } showCalendar(); Quote Link to comment https://forums.phpfreaks.com/topic/205832-calender-problem-help-needed/ Share on other sites More sharing options...
Adam Posted June 25, 2010 Share Posted June 25, 2010 ... and what is wrong with August exactly? Quote Link to comment https://forums.phpfreaks.com/topic/205832-calender-problem-help-needed/#findComment-1077128 Share on other sites More sharing options...
xiaoxin22 Posted June 28, 2010 Author Share Posted June 28, 2010 this is what happened to august... anyone can help? Quote Link to comment https://forums.phpfreaks.com/topic/205832-calender-problem-help-needed/#findComment-1078023 Share on other sites More sharing options...
jcbones Posted June 28, 2010 Share Posted June 28, 2010 Your problem is here: for($i=$firstDay['wday'];$i<=7;$i++){ $actday++; load_events($actday, $month); } Your variable $firstDay['wday'] holds a value from 0(Sunday) - 6(Saturday). This loop is fine while the month starts on any day but Sunday, which would assign the $i = 0, making the count of ($i<=7) = 8; The simple fix for this would be to add this line: // Display the first calendar row with correct positioning echo '<tr>'; //ADD THIS LINE: $firstDay['wday'] = ($firstDay['wday'] == 0) ? 7 : $firstDay['wday']; //This will change the firstDay['wday'] variable to 7 if it's inital value is 0. for($i=1;$i<$firstDay['wday'];$i++){ echo '<td> </td>'; } That is all that I see. Quote Link to comment https://forums.phpfreaks.com/topic/205832-calender-problem-help-needed/#findComment-1078032 Share on other sites More sharing options...
xiaoxin22 Posted June 28, 2010 Author Share Posted June 28, 2010 Your problem is here: for($i=$firstDay['wday'];$i<=7;$i++){ $actday++; load_events($actday, $month); } Your variable $firstDay['wday'] holds a value from 0(Sunday) - 6(Saturday). This loop is fine while the month starts on any day but Sunday, which would assign the $i = 0, making the count of ($i<=7) = 8; The simple fix for this would be to add this line: // Display the first calendar row with correct positioning echo '<tr>'; //ADD THIS LINE: $firstDay['wday'] = ($firstDay['wday'] == 0) ? 7 : $firstDay['wday']; //This will change the firstDay['wday'] variable to 7 if it's inital value is 0. for($i=1;$i<$firstDay['wday'];$i++){ echo '<td> </td>'; } That is all that I see. THANKS!!! it works amazingly!! it is solved.. thank you very much.. haha. Quote Link to comment https://forums.phpfreaks.com/topic/205832-calender-problem-help-needed/#findComment-1078039 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.