Simsonite Posted March 18, 2009 Share Posted March 18, 2009 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] Quote Link to comment Share on other sites More sharing options...
Simsonite Posted March 19, 2009 Author Share Posted March 19, 2009 Can anybody help me? Quote Link to comment Share on other sites More sharing options...
matt.sisto Posted March 19, 2009 Share Posted March 19, 2009 Looks like you have a bug: $query2 = "SELECT * FROM calendar_revents WHERE start<'$firstDay' AND end>'$lastDay'"; $result2 = mysql_query($query2) or die(mysql_error()); is it not supposed to be caledar_events? Quote Link to comment Share on other sites More sharing options...
matt.sisto Posted March 19, 2009 Share Posted March 19, 2009 sorry I meant calendar_events. Quote Link to comment Share on other sites More sharing options...
Simsonite Posted March 19, 2009 Author Share Posted March 19, 2009 actually no this is my events table that holds the events that repeat themselves. Thanks anyway PS. if you think i should remake my calendar from scratch just say. Quote Link to comment Share on other sites More sharing options...
matt.sisto Posted March 19, 2009 Share Posted March 19, 2009 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? Quote Link to comment Share on other sites More sharing options...
Simsonite Posted March 19, 2009 Author Share Posted March 19, 2009 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 Quote Link to comment Share on other sites More sharing options...
matt.sisto Posted March 19, 2009 Share Posted March 19, 2009 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. Quote Link to comment Share on other sites More sharing options...
matt.sisto Posted March 19, 2009 Share Posted March 19, 2009 event_id is on auto increment. Quote Link to comment Share on other sites More sharing options...
Simsonite Posted March 19, 2009 Author Share Posted March 19, 2009 Can i please have a look at your site? Quote Link to comment Share on other sites More sharing options...
matt.sisto Posted March 19, 2009 Share Posted March 19, 2009 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. ??? Quote Link to comment Share on other sites More sharing options...
Simsonite Posted March 19, 2009 Author Share Posted March 19, 2009 ok well in the calendar file you have missed out a ; on line 77. Im guessing that you have some problems with fetching the info from the database. Quote Link to comment Share on other sites More sharing options...
matt.sisto Posted March 19, 2009 Share Posted March 19, 2009 Thanks for the heads up on the bug, do you have an idea why I can't fetch the data from the db? Quote Link to comment Share on other sites More sharing options...
matt.sisto Posted March 19, 2009 Share Posted March 19, 2009 What does your global.php contain? Quote Link to comment Share on other sites More sharing options...
Simsonite Posted March 19, 2009 Author Share Posted March 19, 2009 well database connections and some random functions aswell as some session and cookie stuff Quote Link to comment Share on other sites More sharing options...
matt.sisto Posted March 19, 2009 Share Posted March 19, 2009 So there is nothing in there that I would need to get your script working on my server? Do you remember wher the tutorial was? Quote Link to comment Share on other sites More sharing options...
Simsonite Posted March 19, 2009 Author Share Posted March 19, 2009 I used this tutorial and i added the database connection and event parsing etc. You should be able to modify my code to be used on your server but please dont copy my script exactly http://php.about.com/od/finishedphp1/ss/php_calendar.htm Quote Link to comment Share on other sites More sharing options...
matt.sisto Posted March 19, 2009 Share Posted March 19, 2009 I won't. I'm gonna try to follow the tutorial as you did, thanks. 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.