Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Full calendar doesn't support recurring events out of the box. Here is what I did. </p> <p>When I add an event I have a select box that is for recurring events. Let's say a user selects it to repeat every week. I then insert an event into my events table with a parent ID which will be the same for all the instances of that event. </p> <p>Full calendar makes it so that recurring events have to have the same event ID. So in my events table I have a unique event ID column and a parent ID which is the column I use to render events. </p> <p>So anyway, immediately after I insert the first event I run a loop that selects the last inserted event with the same parent ID, add 7 days to it, and inserts it into the events table. I loop through this process 50 more times and then I have an event that occurs every week for a year. </p> <p>Here's some code:</p> <p>When a user selects a time frame I open a dialog</p> <pre class="lang-js prettyprint-override"><code> select: function(start, end){ $( "#add_class" ).dialog( "open" ); }, </code></pre> <p>On the dialog, I have a drop down select</p> <pre class="lang-html prettyprint-override"><code>&lt;div id="add_class" title="Add New Class"&gt; &lt;form action=""&gt; &lt;div id="recurring_event"&gt; &lt;label for = "recurring"&gt;Recurring &lt;/label&gt; &lt;input type="checkbox" name="recurring" id="recurring" /&gt; &lt;div id = "recurring_options" &gt; Repeat every &lt;select name = "repeat_frequency" id = "repeat_frequency"&gt; &lt;option value ="1"&gt;Day&lt;/option&gt; &lt;option value="7" selected="selected"&gt;Week&lt;/option&gt; &lt;option value = "28"&gt;Month&lt;/option&gt; &lt;/select&gt; &lt;/div&gt; &lt;/div&gt; &lt;/form&gt; &lt;/div&gt; </code></pre> <p>Then I submit this info using AJAX to a php page called add_class.php</p> <pre class="lang-js prettyprint-override"><code>$( "#add_class" ).dialog({ "Save Class": function() { var repeat_frequency = $("#repeat_frequency").val(); $.ajax({ type:"POST", url: "add_class.php", data: "repeat_frequency=" + repeat_frequency, async: false, }); $('#calendar').fullCalendar('refetchEvents'); $( this ).dialog( "close" ); }, Cancel: function() { $( this ).dialog( "close" ); } }, </code></pre> <p>Here comes the add_class.php part where I actually enter it into the database</p> <pre class="lang-php prettyprint-override"><code> $repeat_frequency = $_POST['repeat_frequency']; $dbh = new PDO("mysql:host=$mysql_hostname;dbname=$mysql_dbname", $mysql_username, $mysql_password); $dbh-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION, PDO::MYSQL_ATTR_USE_BUFFERED_QUERY); $stmt = $dbh-&gt;prepare( "INSERT INTO events (start, end) //whatever variables you received from the AJAX post on the dialog form VALUES (:start, :end)"); $stmt-&gt;bindParam(':start', $start); $stmt-&gt;bindParam(':end', $end); $stmt-&gt;execute(); $id = $dbh-&gt;lastInsertId(); for($x = 0; $x &lt; "51"; $x++) { $stmt = $dbh-&gt;prepare(" SELECT start, end FROM events WHERE event_id = :event_id "); $stmt-&gt;bindParam(':event_id', $event_id, PDO::PARAM_STR); $stmt-&gt;execute(); $result = $stmt-&gt;fetch(PDO::FETCH_ASSOC); $start = $result['start']; $end = $result['end']; $start_date= strtotime($start . '+' . $repeat_frequency . 'DAYS'); $end_date= strtotime($end . '+' . $repeat_frequency . 'DAYS'); $start = date("Y-m-d H:i", $start_date); $end = date("Y-m-d H:i", $end_date); unset($stmt); $stmt = $dbh-&gt;prepare( "INSERT INTO events (start, end ) //and whatever other columns you need VALUES (:start, :end)"); $stmt-&gt;bindParam(':start', $start, PDO::PARAM_STR); $stmt-&gt;bindParam(':end', $end, PDO::PARAM_STR); $stmt-&gt;execute(); $event_id = $dbh-&gt;lastInsertId(); } </code></pre> <p>So that's just a general gist of things. Hopefully there are not too many typos as I tried to edit it down to just the essentials to get the point across. Let me know if you have any questions. </p> <p><strong>EDIT</strong></p> <p>To "display" events on fullcalendar you need to have an event source. </p> <p>check out this link </p> <p><a href="http://fullcalendar.io/docs/event_data/events_json_feed/" rel="nofollow">http://fullcalendar.io/docs/event_data/events_json_feed/</a></p> <p>In your json-events.php you echo the event data and then it is displayed on your calendar. </p> <p>Have something like this to show events on your calendar page</p> <pre class="lang-js prettyprint-override"><code>$('#calendar').fullCalendar({ events: '/myfeed.php' }); </code></pre> <p>In your myfeed.php file have something along the lines of</p> <pre class="lang-php prettyprint-override"><code> $dbh = new PDO("mysql:host=$mysql_hostname;dbname=$mysql_dbname", $mysql_username, $mysql_password); $dbh-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // set the error mode to excptions $stmt = $dbh-&gt;prepare("SELECT event_id, title, start, end FROM events ORDER BY start"); $stmt-&gt;execute(); $events = array(); while ($row = $stmt-&gt;fetch(PDO::FETCH_ASSOC)){ //important ! $start = "2010-05-10T08:30"; iso8601 format !! $eventArray['id'] = $row['event_id']; $eventArray['title'] = $row['title']; $eventArray['start'] = $row['start']; $eventArray['end'] = $row['end']; $events[] = $eventArray; echo json_encode($events); </code></pre> <p>If you still have questions then search here on stackoverflow. I think I have explained it pretty well and provided plenty of code. Here is a blog post I made that may also help <a href="http://fajitanachos.com/Fullcalendar-and-recurring-events/" rel="nofollow">http://fajitanachos.com/Fullcalendar-and-recurring-events/</a> I found everything I needed to get fullcalendar running on here and on the fullcalendar home page <a href="http://fullcalendar.io/" rel="nofollow">http://fullcalendar.io/</a></p> <p>I hope this helps. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload