I have 2 SQL query's,
- The first query fetches the device details
- The second query uses the device name from the first query to fetch the status of that device (To see if that device is booked or not).
The output of the 2nd query is supposed to be displayed on the 'fullcalendar' plugin.
fetch_data.php
<?php
//fetch_data.php
include('database.php');
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
if(isset($_POST["btnValue"]))
{
$btnValue = test_input($_POST["btnValue"]);
if ($btnValue == "UE") {
$query = "
SELECT * FROM UE WHERE Device_Type = '$btnValue'
";
}
if ($btnValue == "Server"){
$query = "
SELECT * FROM Servers WHERE Device_Type = '$btnValue'
";
}
if ($btnValue == "Test-Tool"){
$query = "
SELECT * FROM TestTools WHERE Device_Type = '$btnValue'
";
}
$statement = $db_conn->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
$total_row = $statement->rowCount();
$output = '';
$i = 0;
if($total_row > 0)
{
foreach($result as $row)
{
$deviceName = $row['Device_Name'];
$output .= '
<div class="row">
<div style="border:1px solid #ccc; border-radius:5px; padding:16px; margin-bottom:16px; float: left; width: 50%; height:200px;background-color:#FFFFFF;">
<img src="images/'. $row['Device_Image'] .'" alt="" class="img-responsive" style="height: 50px;" >
<p align="left"><strong><a href="#">'. $row['Device_Name'] .'</a></strong></p>
<p style="color:#000000">Capablity : '. $row['Device_Capability'].' <br />
Brand : '. $row['Device_Brand'] .' <br />
Model : '. $row['Device_Model'] .'<br />
Device Type : '. $row['Device_Type'] .' </p>
</div>
<div id="calendar" style="border:1px solid #ccc; border-radius:5px; padding:16px; margin-bottom:16px; float: left; width: 50%; height:200px;background-color:#FFFFFF;">
echo "Helo";
'.$deviceName .'
</div>
</div>
'
;
}
if(!empty($_GET['type']) && $_GET['type'] == 'list'){
// Prepare and execute query
$sql = "SELECT * FROM Booking WHERE Equipment= '.$deviceName .' Status = 'Approved' ";//Loading events for the calendar
$statement = $db_conn->prepare($sql);
$statement->execute();
$result = $statement->fetchAll();
$total_row = $statement->rowCount();
if($total_row > 0)
{
foreach($result as $row)
{
$eventArray[] = $row;
}
}
echo json_encode($eventArray);
}
}else
{
$output = '<h3>No Data Found</h3>';
}
echo $output;
index.php
<!DOCTYPE html>
<html>
<head>
<title> FullCalendar</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css"/>
<script src='js/index.global.js'></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.20.1/moment.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<meta charset='utf-8' />
<style>
body {
margin: 40px 10px;
padding: 0;
font-family: Arial, Helvetica Neue, Helvetica, sans-serif;
font-size: 14px;
}
#calendar {
width: 350px;
height: 250px;
margin: 0 auto;
font-size: 10px;
}
.fc-header-title h2 {
font-size: .9em;
white-space: normal !important;
}
.fc-view-month .fc-event, .fc-view-agendaWeek .fc-event {
font-size: 0;
overflow: hidden;
height: 2px;
}
.fc-view-agendaWeek .fc-event-vert {
font-size: 0;
overflow: hidden;
width: 2px !important;
}
.fc-agenda-axis {
width: 20px !important;
font-size: .7em;
}
.fc-button-content {
padding: 0;
}
</style>
</head>
<body>
<div class="col-md-9">
<br />
<div class="row filter_data">
<div id="calendar" style="border:1px solid #ccc; border-radius:5px; padding:16px; margin-bottom:16px; float: left; width: 50%; height:200px;background-color:#FFFFFF;">
</div>
</div>
</div>
</body>
</html>
<script>
$(document).ready(function(){
filter_data();
function filter_data()
{
$('.filter_data').html('<div id="loading" style="" ></div>');
var action = 'fetch_data';
var brand = get_filter('brand');
var ram = get_filter('ram');
var storage = get_filter('storage');
$.ajax({
url:"fetch_data.php",
method:"POST",
data:{action:action, brand:brand, ram:ram, storage:storage},
success:function(data){
$('.filter_data').html(data);
}
});
}
function get_filter(class_name)
{
var filter = [];
$('.'+class_name+':checked').each(function(){
filter.push($(this).val());
});
return filter;
}
$('.common_selector').click(function(){
filter_data();
});
let btn = document.getElementById("btn");
// Adding event listener to button
btn.addEventListener("click", () => {
// Fetching Button value
let btnValue = btn.value;
// jQuery Ajax Post Request
$.post('fetch_data.php', {
btnValue: btnValue
}, function(response) {
// response from PHP back-end
// console.log(response);
//alert(response)
$('.filter_data').html(response);
});
});
let btn1 = document.getElementById("btn1");
// Adding event listener to button
btn1.addEventListener("click", () => {
// Fetching Button value
let btnValue = btn1.value;
// jQuery Ajax Post Request
$.post('fetch_data.php', {
btnValue: btnValue
}, function(response) {
// response from PHP back-end
// console.log(response);
//alert(response)
$('.filter_data').html(response);
});
});
let btn2 = document.getElementById("btn2");
// Adding event listener to button
btn2.addEventListener("click", () => {
// Fetching Button value
let btnValue = btn2.value;
// jQuery Ajax Post Request
$.post('fetch_data.php', {
btnValue: btnValue
}, function(response) {
// response from PHP back-end
// console.log(response);
//alert(response)
$('.filter_data').html(response);
});
});
let btn3 = document.getElementById("btn3");
// Adding event listener to button
btn3.addEventListener("click", () => {
// Fetching Button value
let btnValue = btn3.value;
// jQuery Ajax Post Request
$.post('fetch_data.php', {
btnValue: btnValue
}, function(response) {
// response from PHP back-end
// console.log(response);
//alert(response)
$('.filter_data').html(response);
});
});
let btn4 = document.getElementById("btn4");
// Adding event listener to button
btn4.addEventListener("click", () => {
// Fetching Button value
let btnValue = btn4.value;
// jQuery Ajax Post Request
$.post('fetch_data.php', {
btnValue: btnValue
}, function(response) {
// response from PHP back-end
// console.log(response);
//alert(response)
$('.filter_data').html(response);
});
});
$('#submit').click(function(){
$('#submit').prop('disabled', true);
var email = $('#email').val();
var psw = $('#psw').val();
if(email == '' || psw == '' )
{
$('#response').html('<span class="text-danger">All Fields are required</span>')
$('#submit').prop('disabled', false);
}
else
{
$.post(
'adminLogin.php',
$('#bookingForm').serialize(),
function(data)
{
//alert(data);
$('form').trigger("reset");
//$(".modal-body").html(data);
$('#submit').prop("disabled", false);
//$('#empModal').modal('show');
window.location.href = 'AdminPanel.php';
}
);
}
});
function getEvent(){
var events = new Array();
$.ajax({
type : "POST",
url : "fetch-test.php?type=list",
dataType : "json",
success : function(data) {
var result = data;
$.each(result, function(i, item){
events.push({
event_id : result[i].id,
title : result[i].Equipment,
start : result[i].StartDate,
end : result[i].EndDate
})
})
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
headerToolbar: {
left: 'prev,next today',
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay,listMonth'
},
initialDate: new Date(),
navLinks: true, // can click day/week names to navigate views
businessHours: true, // display business hours
editable: true,
selectable: true,
weekNumbers: true,
fixedWeekCount: false,
aspectRatio: "3",
events: events
});
calendar.render();
}
})
}
getEvent()
});
</script>
I expected the fullcalendar to display in the right div beside the device information on the left. Each device would have its own unique status displayed within the fullcalendar.