Jump to content

Recommended Posts

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();

Link to comment
https://forums.phpfreaks.com/topic/205832-calender-problem-help-needed/
Share on other sites

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.