Jump to content

php calendar


J-Buck

Recommended Posts

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

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

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.