proctk Posted August 23, 2006 Share Posted August 23, 2006 Hi 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 greatcalendar code[code=php:0]<?phpinclude 'db.php';echo "<html><head><title>Calendar</title><body bgcolor=#FFFFFF><center>";// Check for a Month Change submissionif ($_POST) {// Subtract one from the month for previous, add one for nextif ($_POST["submit"] == "Prev") { $_POST["month_now"]--; } else { $_POST["month_now"]++; }$date = getdate(mktime(0,0,0, $_POST["month_now"],1, $_POST["year_now"]));} 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;}$today++;}// allow for form submission to the script for forward and backwardsecho"<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><inputtype='submit' name='button' value='Next'></td></tr></table></form><table width='160' border='1' cellspacing=0 cellpadding=2><tr><td colspan='7'>$month_name $year</td></tr><tr><td>Su</td><td>M</td><td>T</td><td>W</td><td>Th</td><td>F</td><td>Sat</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 pageif ( 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;else$colour = silver;echo "<td align=center bgcolor=$colour><a href=results.php?eventid=$link_date> $day </a></td>";// show event descriptionif ($wday==6) {echo "</tr>\n";}$wday++;$wday = $wday % 7;$day++;}echo"</table></body></html>";?>[/code]results.php[code=php:0]<? session_start(); // Start Session?><?php$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","");mysql_select_db("mydata",$db);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';exit();}$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 BYevent_date";$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><tr><td><table border=1><tr><td>Date</td><td>Description</td><td>Category</td><td>details</td><td>Delete?</td></tr><?phpwhile ($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 "<inputtype='radio' value='$row[userid],$row[event_id]' name='delete'></td></tr>";}?></table></td></tr></table><input type="hidden" name="event_date" value="<?php echo $eventid;?>"><input type="submit" name="del" value="Delete Event"></form><form method="POST" action="<? echo $PHP_SELF; ?>"><br><br><input type="hidden" name="event_date" value="<?php echo $eventid;?>">Details:<br><textarea name="details" cols="20" rows="5"></textarea><br><input type="hidden" name="<? $_SESSION[user_id]; ?>"><br>Description:<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</select><br><br /><input type="submit" name="submit" value="Add Event"></form><a href="cal.php">Back to the Calendar</a></body></html>[/code]table[code=php:0]<html><head><title>Calendar Table</title></head><body><?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());?> </body></html>[/code] Quote Link to comment Share on other sites More sharing options...
proctk Posted August 23, 2006 Author Share Posted August 23, 2006 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.