Jump to content

Repeat events in calendar?


Simsonite

Recommended Posts

Hi,

 

I am in the process of developing a calendar application, i have made the basic calendar with events being fetched from a mysql database. However i am slightly confused about how i should modify my script to allow repeat events.

 

I will attach my current file

 

Thank you in advance

Daniel

 

[attachment deleted by admin]

Link to comment
Share on other sites

Well I have been trying to do something very similar, I'm building a booking system for a consultancy. I can get the calendar sorted, I can add events to the calendar_events table but getting them to be represented in the calendar is proving difficult. Is urs working, and what is the structure of the table calendar_events?

Link to comment
Share on other sites

Yeah my script works, it is a modified version of a tutorial i found somewhere, i can try and find it again if you want.

 

Here is the structure of my database which is generated with phpmyadmin

 

===Database main

 

== Table structure for table calendar_events

 

|------

|Field|Type|Null|Default

|------

|//**id**//|int(11)|Yes|NULL

|title|varchar(100)|Yes|

|desc|varchar(255)|Yes|

|day|int(11)|Yes|

|month|int(2)|Yes|

|year|int(11)|Yes|

|hour|int(11)|Yes|

|min|int(11)|Yes|

|date|int(11)|Yes|

== Dumping data for table calendar_events

 

|1|First Event|This is my First Event|10|3|2009|0|0|1236668400

|2|Second Event|This is my Second Event|5|3|2009|0|0|1236239744

|3|Third Event|This is my Third Event|17|3|2009|0|0|1237334400

|4|Forth Event|This is my Forth Event|10|4|2009|0|0|1239408000

 

Finally if you want post the structure of your database table and i will see if i can think of a way to create the calendar.

 

Thank you

Daniel

 

Link to comment
Share on other sites

table calendar_events

 

|------

|Field|Type|Null|Default

|------

|//**event_id**//|int(11)|Yes|NULL

|event_title|varchar(200)|No|

|event_shortdesc|varchar(200)|No|

|evetn_startdate|Date|No|0000-00-00

 

I too have been following a tutorial, but from a book called PHP in 24 hours (Sams), but it just doesn't seem to work? I emailed the author but no reply. I fear that the code has some serious issues, it includes 2 scripts:

showcalendar_withevent.php:

<?php
$mysqli = mysqli_connect("localhost", "a*****9", "a*****e", "salmons_reach_org_d*****e");

define("ADAY", (60*60*24));
if ((!isset($_POST["month"])) || (!isset($_POST["year"]))) {
$nowArray = getdate();
$month = $nowArray["mon"];
$year = $nowArray["year"];
} else {
$month = $_POST["month"];
$year = $_POST["year"];
}
$start = mktime (12, 0, 0, $month, 1, $year);
$firstDayArray = getdate($start);
?>
<html>
<head>
<title><?php echo "Calendar: ".$firstDayArray["month"]." ".$firstDayArray["year"] ?></title>
<head>
<script type="text/javascript">
function eventWindow(url) {
event_popupWin = window.open(url, 'event', 'resizable=yes,scrollbars=yes,toolbar=no,width=400,height=400');
event_popupWin.opener = self;
}
</script>
<body>
<h1>Select a Month/Year Combination</h1>
<form method="post" action="<?php echo $_SERVER["PHP_SELF"]; ?>">
<select name="month">
<?php
$months = Array("January", "February", "March", "April", "May",  "June", "July", "August", "September", "October", "November", "December");
for ($x=1; $x <= count($months); $x++) {
echo"<option value=\"$x\"";
if ($x == $month) {
	echo " selected";
}
	echo ">".$months[$x-1]."</option>";
}
?>
</select>
<select name="year">
<?php
       $yeartoday = date(Y);
       $yearplus1 = date(Y)+1;
    for($x=$yeartoday;$x<=$yearplus1;$x++){ 
echo "<option";
if ($x == $year) {
	echo " selected";
}
echo ">$x</option>";
}
?>
</select>
<input type="submit" name="Submit" value="Go!">
</form>
<br/>
<?php
$days = Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
echo "<table border=\"1\" cellpadding=\"5\"><tr>\n";
foreach ($days as $day) {
echo "<td style=\"background-color: #CCCCCC; text-align: center; width: 14%\">
      <strong>$day</strong></td>\n";
}

for ($count=0; $count < (6*7); $count++) {
$dayArray = getdate($start);
if (($count % 7) == 0) {
	if ($dayArray["mon"] != $month) {
		break;
	} else {
		echo "</tr><tr>\n";
	}
}
if ($count < $firstDayArray["wday"] || $dayArray["mon"] != $month) {
	echo "<td> </td>\n";
} else {
	$chkEvent_sql = 3
	$chkEvent_res = mysqli_query($mysqli, $chkEvent_sql) or die(mysqli_error($mysqli));

	if (mysqli_num_rows($chkEvent_res) > 0) {
		$event_title = "<br/>";
		while ($ev = mysqli_fetch_array($chkEvent_res)) {
			$event_title .= stripslashes($ev["event_title"])."<br/>";
		}
		mysqli_free_result($chkEvent_res);
	} else {
		$event_title = "";
	}


	unset($event_title);

	$start += ADAY;
}
}
echo "</tr></table>";
mysqli_close($mysqli);
?>
</body>
</html>

 

and the event.php:

<html>
<head>
<title>Show/Add Events</title>
<head>
<body>
<h1>Show/Add Events</h1>
<?php
$mysqli = mysqli_connect("localhost", "a*****9", "a*****e", "salmons_reach_org_d*****e");
//add any new event
if ($_POST) {
$m = $_POST["m"];
$d = $_POST["d"];
$y = $_POST["y"];

$event_date = $y."-".$m."-".$d." ".$_POST["event_time_hh"].":".$_POST["event_time_mm"].":00";

$insEvent_sql = "INSERT INTO calendar_events (event_title, event_shortdesc, event_start) VALUES('".$_POST["event_title"]."', '".$_POST["event_shortdesc"]."', '$event_date')";
$insEvent_res = mysqli_query($mysqli, $insEvent_sql) or die(mysqli_error($mysqli));
} else {
$m = $_GET["m"];
$d = $_GET["d"];
$y = $_GET["y"];
}
//show events for this day
$getEvent_sql = "SELECT event_title, event_shortdesc, date_format(event_start, '%l:%i %p') as fmt_date FROM calendar_events WHERE month(event_start) = '".$m."' AND dayofmonth(event_start) = '".$d."' AND year(event_start) = '".$y."' ORDER BY event_start";
$getEvent_res = mysqli_query($mysqli, $getEvent_sql) or die(mysqli_error($mysqli));

if (mysqli_num_rows($getEvent_res) > 0) {
$event_txt = "<ul>";
while ($ev = @mysqli_fetch_array($getEvent_res)) {
	$event_title = stripslashes($ev["event_title"]);
	$event_shortdesc = stripslashes($ev["event_shortdesc"]);
	$fmt_date = $ev["fmt_date"];

	$event_txt .= "<li><strong>".$fmt_date."</strong>: ".$event_title."<br/>".$event_shortdesc."</li>";
}
$event_txt .= "</ul>";
mysqli_free_result($getEvent_res);
} else {
$event_txt = "";
}

mysqli_close($mysqli);

if ($event_txt != "") {
echo "<p><strong>Today's Events:</strong></p>
$event_txt
<hr/>";
}

// show form for adding an event
echo "
<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">
<p><strong>Would you like to add an event?</strong><br/>
Complete the form below and press the submit button to add the event and refresh this window.</p>
<p><strong>Event Title:</strong><br/>
<input type=\"text\" name=\"event_title\" size=\"25\" maxlength=\"25\"/>
<p><strong>Event Description:</strong><br/>
<input type=\"text\" name=\"event_shortdesc\" size=\"25\" maxlength=\"255\"/>
<p><strong>Event Time (hh:mm):</strong><br/>
<select name=\"event_time_hh\">";
for ($x=1; $x <= 24; $x++) {
echo "<option value=\"$x\">$x</option>";
}
echo "</select> :
<select name=\"event_time_mm\">
<option value=\"00\">00</option>
<option value=\"15\">15</option>
<option value=\"30\">30</option>
<option value=\"45\">45</option>
</select>
<input type=\"hidden\" name=\"m\" value=\"".$m."\">
<input type=\"hidden\" name=\"d\" value=\"".$d."\">
<input type=\"hidden\" name=\"y\" value=\"".$y."\">
<br/><br/>
<input type=\"submit\" name=\"submit\" value=\"Add Event\">
</form>";
?>
</body>
</html>

Any help would be greatly appreciated. 8)

 

Link to comment
Share on other sites

At the moment it is very basic, I'm just trying to get the major functioning components working and then progress to creating its structure and generating the CSS, but this is a link to the showcalendar.php script:

 

http://salmonsreach.org/calender/showcalender.php

 

showcalendar_withevent.php:

http://salmonsreach.org/calender/showcalender_withevent.php

 

this is not working, and neither is the event.php:

http://salmonsreach.org/calender/event.php

 

it is a mystery, as I have followed the tutorial to a t, and gone over it several times. ???

 

 

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.