Moorcam Posted July 13, 2021 Share Posted July 13, 2021 Hi guys, I am trying to display tour information in fullcalendar but nothing is happening and no errors. Here is the php code from fetch-tours.php <?php require_once "config.php"; $json = array(); $sqlQuery = "SELECT * FROM jobs ORDER BY id"; $result = mysqli_query($con, $sqlQuery); $eventArray = array(); while ($row = mysqli_fetch_assoc($result)) { $title = isset($row['name']); $start = isset($row['dep_date']); $end = isset($row['ret_date']); $eventsArray['title'] = $title; $eventsArray['start'] = $start; $eventsArray['end'] = $end; array_push($eventArray, $row); } mysqli_free_result($result); mysqli_close($con); echo json_encode($eventArray); ?> And here is the Javascript that displays the calendar: <script type="text/javascript"> $(document).ready(function() { var date = new Date(); var d = date.getDate(); var m = date.getMonth(); var y = date.getFullYear(); $('#calendar').fullCalendar( { header: { left: 'prev,next today', center: 'title', right: 'month,basicWeek,basicDay' }, editable :true, events: "includes/fetch-tours.php", }); }) </script> The calendar displays fine but just no data. Any help is greatly appreciated. Cheers, Dan Quote Link to comment https://forums.phpfreaks.com/topic/313077-fullcalendar-not-displaying-data-from-mysql/ Share on other sites More sharing options...
requinix Posted July 13, 2021 Share Posted July 13, 2021 $title = isset($row['name']); $start = isset($row['dep_date']); $end = isset($row['ret_date']); Are you sure that's what you want to do with those variables? Quote Link to comment https://forums.phpfreaks.com/topic/313077-fullcalendar-not-displaying-data-from-mysql/#findComment-1588295 Share on other sites More sharing options...
Moorcam Posted July 13, 2021 Author Share Posted July 13, 2021 (edited) 20 minutes ago, requinix said: $title = isset($row['name']); $start = isset($row['dep_date']); $end = isset($row['ret_date']); Are you sure that's what you want to do with those variables? I have changed that now. All I want to do is display the name, start date and finish date in the calendar. $data = array(); $query = "SELECT * FROM tours ORDER BY id"; $statement = $con->prepare($query); $statement->execute(); $result = $statement->fetchAll(); foreach ($result as $row) { $data[] = array( 'id' => $row["id"], 'title' => $row["name"], 'start' => $row["dep_date"], 'end' => $row['ret_date'] ); } echo json_encode($data); I have never used calendars before and am clueless with Javascript etc so any help with this would be appreciated. Edited July 13, 2021 by DanEthical Quote Link to comment https://forums.phpfreaks.com/topic/313077-fullcalendar-not-displaying-data-from-mysql/#findComment-1588296 Share on other sites More sharing options...
requinix Posted July 13, 2021 Share Posted July 13, 2021 Seems alright, but there are 5 versions of FullCalendar and I don't know which one you're using. Check the browser's error console for any messages, and use its request monitoring tools to make sure that your fetch-tours.php really is being called and returning the data you think it is. Quote Link to comment https://forums.phpfreaks.com/topic/313077-fullcalendar-not-displaying-data-from-mysql/#findComment-1588298 Share on other sites More sharing options...
Moorcam Posted July 13, 2021 Author Share Posted July 13, 2021 5 minutes ago, requinix said: Seems alright, but there are 5 versions of FullCalendar and I don't know which one you're using. Check the browser's error console for any messages, and use its request monitoring tools to make sure that your fetch-tours.php really is being called and returning the data you think it is. Hi mate, Nothing in console. Just a few things with datatables, which I am aware of. Is there an alternative calendar script that I can use that you would recommend? Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/313077-fullcalendar-not-displaying-data-from-mysql/#findComment-1588299 Share on other sites More sharing options...
requinix Posted July 13, 2021 Share Posted July 13, 2021 What I would recommend is not abandoning this because you're having a small problem. Did you confirm that fetch-tours.php is executing and returning the correct data? Quote Link to comment https://forums.phpfreaks.com/topic/313077-fullcalendar-not-displaying-data-from-mysql/#findComment-1588300 Share on other sites More sharing options...
Solution Barand Posted July 13, 2021 Solution Share Posted July 13, 2021 Do not use SELECT * Specify what you want and your (PDO) code becomes $query = "SELECT id , name as title , dep_date as start , ret_date as end FROM tours ORDER BY id"; $result = $con->query($query); echo json_encode($result->fetchAll()); Quote Link to comment https://forums.phpfreaks.com/topic/313077-fullcalendar-not-displaying-data-from-mysql/#findComment-1588302 Share on other sites More sharing options...
Moorcam Posted July 13, 2021 Author Share Posted July 13, 2021 5 hours ago, requinix said: What I would recommend is not abandoning this because you're having a small problem. Did you confirm that fetch-tours.php is executing and returning the correct data? Hi mate, Did a Var dump (I think) and this is what it showed: object(mysqli_result)#2 (5) { ["current_field"]=> int(0) ["field_count"]=> int(1) ["lengths"]=> array(1) { [0]=> int(1) } ["num_rows"]=> int(1) ["type"]=> int(0) } Quote Link to comment https://forums.phpfreaks.com/topic/313077-fullcalendar-not-displaying-data-from-mysql/#findComment-1588308 Share on other sites More sharing options...
Moorcam Posted July 13, 2021 Author Share Posted July 13, 2021 Got is working <?php require_once "config.php"; $json = array(); $sqlQuery = "SELECT id, name AS title, dep_date AS start, ret_date AS end FROM jobs ORDER BY id"; $result = mysqli_query($con, $sqlQuery); $eventArray = array(); while ($row = mysqli_fetch_assoc($result)) { array_push($eventArray, $row); } mysqli_free_result($result); mysqli_close($con); echo json_encode($eventArray); ?> Thank you both so much for your help. Love your work. Quote Link to comment https://forums.phpfreaks.com/topic/313077-fullcalendar-not-displaying-data-from-mysql/#findComment-1588309 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.