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
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
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
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
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
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
Share on other sites

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
Share on other sites

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
Share on other sites

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