Jump to content

Recommended Posts

hi guys well i have this code for a calender:

<?php
//Here is Step 1.

$date =time () ; //Gets today’s date
$day = date('d', $date) ; //gets the day
$month = date('m', $date) ;//gets the month
$year = date('Y', $date) ;//gets the year
$firstDay = mktime(0,0,0,$month, 1, $year) ;//gets the first day of the month.
$monthName = date('F', $firstDay) ; //gets the month name

//Here is Step 2

$firstDayOfWeek = date('D', $firstDay) ;  //gets the day of the week for the first of the month.

// Here is Step 3

switch($firstDayOfWeek){
case "Sun": $spacer = 0; break;
case "Mon": $spacer = 1; break;
case "Tue": $spacer = 2; break;
case "Wed": $spacer = 3; break;
case "Thu": $spacer = 4; break;
case "Fri": $spacer = 5; break;
case "Sat": $spacer = 6; break;
}

//Here is Step 4

$daysInMonth = cal_days_in_month(0, $month, $year) ; //gets number of days in month 

//Here is Step 5

echo "<table border=2 width=350>";  //The next few lines set up the table and the day headers.
echo "<tr><th colspan=7> $monthName $year </th></tr>";
echo "<tr><td width=50>S</td><td width=50>M</td><td width=50>T</td><td width=50>W</td><td width=50>T</td><td width=50>F</td><td width=50>S</td></tr>";
$dayCount = 1; //counts the number of days.  We only want it to count up to 7.
echo "<tr>";
while ( $spacer > 0 )   //Start with the blank days in the beginning of the month.
{
echo "<td></td>";
$spacer = $spacer-1;
$dayCount++;
}
$dayNumber = 1;  // first we must set a counter to so we can print out the days.

while ( $dayNumber <= $daysInMonth ) //While loop will print out the days as long as there are days left in the month.
{                                                                       
echo "<td> $dayNumber </td>";
$dayNumber++;
$dayCount++;

if ($dayCount > 7)  //Makes sure we only print out seven days per week.
{
echo "</tr><tr>";
$dayCount = 1;
}
}
while ( $dayCount >1 && $dayCount <=7 ) //We print blanks at the end of the month.
{
echo "<td> </td>";
$dayCount++;
}

echo "</tr></table>"; //End the table for the calendar. 

?>






 

now the problem is that the code is echoing itself after a certian point:

output:

"; //The next few lines set up the table and the day headers. echo " "; echo "SMTWTFS"; = 1; //counts the number of days. We only want it to count up to 7. echo ""; while ( > 0 ) //Start with the blank days in the beginning of the month. { echo ""; = -1; ++; } = 1; // first we must set a counter to so we can print out the days. while ( <= ) //While loop will print out the days as long as there are days left in the month. { echo " "; ++; ++; if ( > 7) //Makes sure we only print out seven days per week. { echo ""; = 1; } } while ( >1 && <=7 ) //We print blanks at the end of the month. { echo " "; ++; } echo ""; //End the table for the calendar. ?>

 

now the thing is it is only doing this if i put it inside another page, if it is simply run by itself it works fine,

code is attached as new restrictions will not allow me to post it for some reason

 

cheers matt

 

Link to comment
https://forums.phpfreaks.com/topic/93973-php-echiong-itself/
Share on other sites

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.