Friday 20 May 2022

DataTables warning: table id=example - Invalid JSON response: How to Debug?

  1. Use CTRL+SHIFT+I (or navigate to Current Page Control > Developer > Developer Tools. In the newer versions of Chrome, click the Wrench icon > Tools > Developer Tools.) to enable the Developer Tools.
  2. From within the developer tools click on the Network button. 
  3. Click the "XHR" sub-button.
  4. Initiate an AJAX call.
  5. Double click the Name of the page under the Network button. It will open a new page with the details of the error. 

Wednesday 11 May 2022

Prevent caching data from database in PhP FullCalendar

 <script>
document.addEventListener('DOMContentLoaded', function() {     
        var calendarEl = document.getElementById('calendar');
        var events = [];
        var eventsCache = {};
        var calendar = new FullCalendar.Calendar(calendarEl, {       
        headerToolbar: {
        left: 'prev,next today',
        center: 'title',
        right: 'dayGridMonth,timeGridWeek,timeGridDay,listWeek'
      },     
          eventSources: [{
            cache: false,
              url: 'loadevent.php',
              type: 'POST',
              extraParams: function() {        //  Prevent caching data from database in fullcalendar
                  return {
                    cachebuster: new Date().valueOf()
                  };
                },             
          }],     
    });       
        calendar.render();
        calendar.refetchEvents();       
});   
</script>

Friday 6 May 2022

How to configure PHP Calendar with events from database?

Download fullcalendar  file  from : https://github.com/fullcalendar/fullcalendar/releases

PhP Page

Inside <HEAD> Tag

<link href='fullcalendar-5.10.2/lib/main.min.css' rel='stylesheet' /> // GIVE EXACT FILE PATH   main.min.css, main.min.js
<script src='fullcalendar-5.10.2/lib/main.min.js'></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
        var calendarEl = document.getElementById('calendar');       
        var calendar = new FullCalendar.Calendar(calendarEl, {     
        headerToolbar: {
        left: 'prev,next today',
        center: 'title',
        right: 'dayGridMonth,timeGridWeek,timeGridDay,listWeek'
      },  
      events: 'loadevent.php',
        },             
            displayEventTime: false,
            selectHelper:true,
            weekNumbers: true,
            navLinks: true, // can click day/week names to navigate views
            nowIndicator: true,
            weekNumbers: true,
            dayMaxEventRows: true, // for all non-TimeGrid views
              views: {
                timeGrid: {
                  dayMaxEventRows: 6 // adjust to 6 only for timeGridWeek/timeGridDay
                }
              },         
    });
          calendar.render();
});   
    </script>

Inside BODY Tag

<body>
<div class="container">
<div class="row">
<div class="col-md-12">
<h1 align="center" style=" padding: 3%;"> Calendar Heading</h1>  
<div id='calendar'></div>
</div>
</div>
</div>
</body>

loadevent.php

--> Database connection establishment

$data = array();
$stmt = $con->prepare(" SQL QUERY  ");
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
    $data[] = array(
        'id'   => $row["No"],
        'title'   => $row["title"],                                                                            // DB ATTRIBUTE NAME FOR TITLE
        'start'   => $row["DATE1"],                                                                     // DB START DATE ENTRY in yy-mm-dd 00:00:00 format
        'end'   => $row["DATE2"],                                                                     // DB END DATE ENTRY in yy-mm-dd 00:00:00 format
        'description' =>   $row[" Description "],    // DB Description attribute
      
    );
    //result is in row
}

echo json_encode($data);

Tuesday 3 May 2022

Warning: mysqli_query() expects parameter 1 to be mysqli, resource given

Reason for the error:
You are mixing mysqli and mysql extensions in the code, which will not work. mysqli has many improvements over the original mysql extension, so it is recommended to use mysqli .