Jump to content


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


calendar link

Recommended Posts


With the help of many tutorials and code I found and edited I have created a calender that displays the current month with the days of the month available as a link to a schedual of events.

I'm trying to get the discription for the events to display on the calendar under the correct date.  I can get the descriptions to display but I cannot figure out how to get the description under the correct date.

I posted all code related to my calendar any help or guidanace would be great

calendar code


include 'db.php';

echo "
<body bgcolor=#FFFFFF>

// Check for a Month Change submission
if ($_POST) {

// Subtract one from the month for previous, add one for next

if ($_POST["submit"] == "Prev") {
} else {
$_POST["month_now"]++; }

$date = getdate(mktime(0,0,0,

} else {
$date = getdate();

$month_num = $date["mon"];
$month_name = $date["month"];
$year = $date["year"];
$date_today = getdate(mktime(0,0,0,$month_num,1,$year));
$first_week_day = $date_today["wday"];
$cont = true;
$today = 27;

while (($today <= 32) && ($cont)) {
$date_today = getdate(mktime(0,0,0,$month_num,$today,$year));

if ($date_today["mon"] != $month_num) {
$lastday = $today - 1;
$cont = false;


// allow for form submission to the script for forward and backwards

<form  method='POST' name='calendar' action='cal.php'>

<input type='hidden' name='month_now' value='$month_num'>
<input type='hidden' name='year_now' value='$year'>
<table width='200'>
<tr><td><input type='submit' name='submit' value='Prev'></td>
    <td align=right><input
type='submit' name='button' value='Next'></td>

<table width='160' border='1' cellspacing=0 cellpadding=2>
<tr><td colspan='7'>$month_name $year</td></tr>

// begin placement of days according to their beginning weekday

$day = 1;
$wday = $first_week_day;
$firstweek = true;
while ( $day <= $lastday) {

$month_day = ($year.'-'.$month_num.'-'.$day);

if ($firstweek) {
echo "<TR>";
for ($i=1; $i<=$first_week_day; $i++) {

echo "<TD>  </td>";
$firstweek = false;
if ($wday==0) {
echo "<tr>";


$cal_description = mysql_query("SELECT * FROM calendar WHERE event_date = '$month_day'") or die (mysql_error());

while ($r=mysql_fetch_assoc($cal_description)){

$event_description = $r['event_description'];

/*echo $event_description*/;


// make each day linkable to the following result.php page

if ( intval($month_num) < 10) { $new_month_num = "0$month_num"; }
elseif (intval($month_num) >= 10) { $new_month_num = $month_num; }
if ( intval($day) < 10) { $new_day = "0$day"; }
elseif (intval($day) >= 10) { $new_day = $day; }
$link_date = "$year-$new_month_num-$new_day";

// add some color and make todays dat stand  out
$today_year = date("Y");
$today_month = date("F");
$today_day = date("j");

if($day == $today_day && $month_name ==
$today_month && $year == $today_year)
$colour = orange;
$colour = silver;
echo "<td align=center bgcolor=$colour><a href=results.php?eventid=$link_date> $day </a></td>";

// show event description

if ($wday==6) {
echo "</tr>\n";

$wday = $wday % 7;




<? session_start();  // Start Session?>


$user_id = $_SESSION['user_id'];

$eventid = $_REQUEST['eventid'];
$del = $_POST['del'];
$delete = $_POST['delete'];
$event_description = $_POST['description'];
$event_category = $_POST['category'];
$event_details = $_POST['details'];
$event_date = $_POST['event_date'];
$userid = $_POST['userid'];
$submit = $_POST['submit'];

echo "<html><body bgcolor=#FFFFFF>";
echo "<form method=\"POST\" action=\"results.php\">";
$db = mysql_connect("localhost","root","");

if ($del) {
$array = explode(",",$delete);

$sql = "DELETE FROM calendar WHERE userid='$array[0]' AND event_id='$array[1]'";
$result = mysql_query($sql, $db) or die ("Invalid query".mysql_error());

if ($submit) {

if($event_description == ""){

echo 'Description is a required field';

$sql = ("INSERT INTO calendar
(event_date, event_description, event_category, event_details, userid) VALUES('$event_date', '$event_description', '$event_category', '$event_details', '$user_id')");

$result = mysql_query($sql, $db) or die ("Insert ERROR: Invalid query" .mysql_error());

echo "<b>Submission Added</b><br><br>";

$sql = "SELECT * from calendar where event_date LIKE '$eventid%' ORDER BY
$result = mysql_query($sql, $db) or die ("Invalid query");

if (!mysql_num_rows($result)) {
echo "I'm sorry, but there are no events for that date.";
} else {
echo "For $eventid the following events have been located:";}

<br><hr noshade>
<table cellpadding=0 cellspacing=0 width=300>
<table border=1>


while ($row = mysql_fetch_array($result)){

echo "<tr><td>$row[event_date]</td><td>";
echo "$row[event_description]</td><td>";
echo "$row[event_category]</td><td>";
echo "$row[event_details]</td><td>";

echo "<input
type='radio' value='$row[userid],$row[event_id]' name='delete'></td></tr>";


<input type="hidden" name="event_date" value="<?php echo $eventid;?>">
<input type="submit" name="del" value="Delete Event">
<form method="POST" action="<? echo $PHP_SELF; ?>"><br><br>

<input type="hidden" name="event_date" value="<?php echo $eventid;?>">

<textarea name="details" cols="20" rows="5"></textarea>

<input type="hidden" name="<? $_SESSION[user_id]; ?>"><br>
<input type="text" name="description"><br><br />

Category:<br />
<select name="category">
<option value="Family Event">Family Event
<option value="Birthday">Birthday
<option value="Aniversery">Anniversary
<option value="Family Trip">Family Trip
<option value="Other">Other

<br><br />

<input type="submit" name="submit" value="Add Event">
<a href="cal.php">Back to the Calendar</a>


<html><head><title>Calendar Table</title></head>



include 'db.php';

mysql_query("CREATE TABLE calendar (
event_id int(25) NOT NULL auto_increment,
userid varchar(255) NOT NULL,
event_description varchar(50),
event_category varchar(255) NOT NULL,
event_details varchar(255) NOT NULL,
event_date date NOT NULL,
PRIMARY KEY (event_id)
)")or die("Create table Error: ".mysql_error());




Share this post

Link to post
Share on other sites
HI, I know this is a long winded post, I thought I would post all code for the calendar as it works great. and is probely the easiest to implement. I'm trying to make it more complicted by addeding to each table cell and that it where I'm having a hard time. I have been working at this for a fews days know.

thank you

Share this post

Link to post
Share on other sites


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.