<?php
// Connect to database server to write clean the table and write new entries.
include(“xxxxxxxxServer.php”);
echo “<br />”;
echo “<br />”;
$temp = “truncate todaysevents;”;
if(!$result = $con->query($temp)){
die(‘There was an error running the query [‘ . $con->error . ‘]’);
}
echo “Done ” .$temp;
echo “<br />”;
echo “<br />”;
echo “<br />”;
// now the Database is empty it is time to get the info. We use today plus 2 days.
// that should get tomorrows events.
$startDate = date(‘Y-m-d’);
$addTimeToDate = date(‘Y-m-d’,strtotime(‘+2 day’,strtotime($startDate)));
$endDate = $addTimeToDate;
echo $startDate;
echo “<br />”;
echo $endDate;
echo “<br />”;
// use the API/JSON to collect the data.
// the dates are variables created above..
$jsonlink = “https://dayboroevents.com/wp-json/stec/v2/get/events/”.$startDate.”/”.$endDate;
echo $jsonlink;
echo “<br />”;
echo “<br />”;
// Read JSON file
$json = file_get_contents($jsonlink);
//Decode JSON
$json_data = json_decode($json,true);
// Loop through the json file to find all the events.
// We then get the Event?Status and the Eventlink to put into our database.
foreach($json_data as $elem) {
( $elem[‘data’]);
foreach ($elem[‘events’] as $events ) {
$EventStatus = ($events[‘event_status’]);
echo “Event Status “.$EventStatus;
$permalink = ($events[‘permalink’]);
echo ” this is the permalink “.$permalink;
echo(“<br/>”) ;
// database fields values are the values taken from the $filename content that is converted in the above section.
$sql = “INSERT INTO `todaysevents`(EventStatus, EventLink)
VALUES
(‘$EventStatus’, ‘$permalink’)”;
echo “Start Running Query”;
if(!$result = $con->query($sql)){
die(‘There was an error running the query [‘ . $con->error . ‘]’);
}
}
}
?>x