/    Sign up×
Community /Pin to ProfileBookmark

How to: Make a simple calender in PHP.

This is all one page called: calender.php. I tried to seperate the different code using the unique tage for each but all the code presented should be in one page. Feel free to try it out and make mods accordingly, also present new ideas or adjustments made for debugging purposes. Thanks! enjoy.

[code=php]
<?php

function display_calender() {

$start_day = date(“w”, mktime(0, 0, 0, date(‘n’), 1, date(‘Y’)));
$month_days = date(“t”);
$today = strtoupper(date(“F Y”));

echo (“<table class=’calender’>n<tr>n”);
echo (“<td colspan=’7′>$today</td>n</tr>n<tr>n”);
echo (“<th>S</th><th>M</th><th>T</th><th>W</th><th>T</th><th>F</th><th>S</th>n</tr>n<tr>n”);

for ($i=0; $i<$start_day; $i++) {
echo (“<td>&nbsp;</td>”);

}

for ($j=1; $j<=$month_days; $j++) {

if ($j == date(‘j’)) {
echo (“<td class=’todays_date’>$j</td>”);
}else{
echo (“<td>$j</td>”);
}

if (($j+$start_day)%7 == 0) {
echo (“n</tr>n<tr>n”);
}
}

echo (“n</tr>n</table>n”);

}

?>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html dir=”ltr” lang=”en”>
<head>
<title>Calender</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=ISO-8859-1″ />
<meta name=”keywords” content=”” />
<meta name=”description” content=”” />
<style type=”text/css”>
<!–
.calender {
text-align: center;
background: #e5e5e5;
color: #800000;
border: 1px solid silver;
}
.calender tr td {
border: 1px solid silver;
}
.todays_date {
background: #800000;
color: #e5e5e5;
}
–>
</style>
</head>
<body>

<?php display_calender(); ?>

</body>
</html>
[/code]

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@CrazyMerlinMar 10.2006 — have you read chapter 10 of the PHP manual?

there is also a PEAR package for calendar building.

it's called Calendar (strange) and provides an API for building calendar data structures.

it can also be easily attached to an underlying data store for event propagation
Copy linkTweet thisAlerts:
@rch10007authorMar 10.2006 — Hey Crazy,

I was reading it (Ch 10) when I got a 'DING' you got mail form WD.

I was trying to find out how the calender functions would create a simple calender to just show the current month. I couldn't figure it out so I wrote the little function above.

I am very curious as to create a functional calender for planning activities. One where different users can put their own content and such - but for now that's way over my head.

Have you built any?
Copy linkTweet thisAlerts:
@welshMar 10.2006 — a database would make doing that a whole lot easier.
Copy linkTweet thisAlerts:
@chazzyMar 10.2006 — if you do use a database for the events, the page should call all data for the date range (start to end of month) and just pull out the day needed from the data in question (use array searching, or just chop off when used [make sure there is entry for each day])
×

Success!

Help @rch10007 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...