I'm making a Wordpress-plugin in which an administrator can add events. Visitors can see a calendar (fullcalendar) where they should see events. However, it does not read the json string which stores all the information. The string looks okay: [{"title":"Evenement01","start":"2013-11-15"},{"title":"Testevenemn12","start":"2013-11-22"}].
Below my json-feed.php code:
<?php
global $wpdb;
$rst_events_array = array();
$rst_get_events = $wpdb->get_results("
SELECT *
FROM wp_rst_events
");
foreach ($rst_get_events as $val){
$rst_events_array [] = array(
'title' => $val->rst_event_name,
'start' => $val->rst_event_date
);
}
echo json_encode($rst_events_array);
?>
And here my jQuery:
jQuery('#rst-calendar').fullCalendar({
events: 'json-feed.php'
});
Thanks in advance
I had the same issue with Wordpress and needed to add;
header("Content-Type: application/json; charset=UTF-8");
echo event::jsonCalendarEvent($id);
exit;
JSON is very particular and any characters after your echo will kill it on the client side.
You should use date/time format as specified in documentation:
The date/time an event begins. When specifying Event Objects for
events or eventSources, you may specify a string in IETF format (ex:
"Wed, 18 Oct 2009 13:00:00 EST"), a string in ISO8601 format (ex:
"2009-11-05T13:15:30Z") or a UNIX timestamp.
So, in your case:
events: [
{
"title":"Evenement01",
"start":"2013-11-15T13:15:30Z"
},
{
"title":"Testevenemn12",
"start":"2013-11-22T13:15:30Z"
}
]
Have a look here.
If you want the event lasts all day, you should set the allDay properties to true.
Related
I have a json output from a database quesry that looks as follows:
[
{
"name": 1,
"value": "27.18161362"
},
{
"name": 2,
"value": "323.69645128"
},
{
"name": 3,
"value": "23.16249181"
}
]
I am trying to plug this into a script that will make charts from the data. The script requires the data to be in the following format:
{"script":
[
{"name":"1","value":27.18161362},
{"name":"2","value":323.69645128},
{"name":"3","value":23.16249181}
]
}
If it is not formatted in this way, the script claims that it is not valid json and contains no valud json head.
The output does use a valid json content header but that appears not to be enough for the script I am using.
So the question is, how can I convert the json output from a database call shown in first example, into the format the script is looking for show in the second example.
Code that creates json is fairly standard:
$stmt = $db3->prepare("SELECT week AS name, SUM(he.earnings) AS value FROM hotspot_earnings he INNER JOIN emrit_hotspots eh ON eh.hotspot_name = he.hotspot_name WHERE year = '2020' GROUP BY year, week");
$stmt->execute();
$row = $stmt->fetchAll(PDO::FETCH_ASSOC);
header('Content-type: application/json; charset=UTF-8');
echo json_encode($row, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
$stmt = $db3->prepare("SELECT week AS name, SUM(he.earnings) AS value FROM hotspot_earnings he INNER JOIN emrit_hotspots eh ON eh.hotspot_name = he.hotspot_name WHERE year = '2020' GROUP BY year, week");
$stmt->execute();
// Change here
$row = ['script' => $stmt->fetchAll(PDO::FETCH_ASSOC)];
Not sure if you can edit the initial json output with php. If it's called by AJAX and you can control the php file you can try something like this. Just build the new array.
$new_array = array('script' => $row);
echo json_encode($new_array, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
I am using a Mailgun Webhook to track events (delivered, opened, etc). I successfully redirected the event to a url that has a php file that looks like this:
<?php
$postdata = file_get_contents("php://input");
$postdata_encoded = json_encode($_POST['message-headers']);
When I echo the output I am getting the following:
[[\"Received\", \"by luna.mailgun.net with SMTP mgrt 8734663311733; Fri, 03 May 2013 18:26:27 +0000\"], [\"Content-Type\", [\"multipart/alternative\", {\"boundary\": \"eb663d73ae0a4d6c9153cc0aec8b7520\"}]], [\"Mime-Version\", \"1.0\"], [\"Subject\", \"Test deliver webhook\"], [\"From\", \"Bob \"], [\"To\", \"Alice \"], [\"Message-Id\", \"<20130503182626.18666.16540#mail.example.com>\"], [\"X-Mailgun-Variables\", \"{\\"my_var_1\\": \\"Mailgun Variable #1\\", \\"my-var-2\\": \\"awesome\\"}\"], [\"Date\", \"Fri, 03 May 2013 18:26:27 +0000\"], [\"Sender\", \"bob#mail.example.com\"]]
Question: How can I transform this output to a proper json format that I will be able to pass to my database? I tried something like this:
$output = array();
foreach ($postdata_encoded as $key=>$value) {
$output[$key] = $value;
}
var_dump($output);
but this returns:
Response: array(0) { }
Any idea? Many thanks
I am using devbay's eBay SDK for PHP.
By default SoldReport is returning the last 30 days.
I'm trying to filter the date range to specify one-day/24 hour period.
I'm assuming I need to include a date range filter somewhere in the StartDownloadJobRequest call.
$startDownloadJobRequest = new BulkDataExchange\Types\StartDownloadJobRequest();
$startDownloadJobRequest->downloadJobType = 'SoldReport';
$startDownloadJobRequest->UUID = uniqid();
$startDownloadJobRequest->downloadRequestFilter = new BulkDataExchange\Types\DownloadRequestFilter();
$startDownloadJobRequest->downloadRequestFilter->activeInventoryReportFilter = $activeInventoryReportFilter;
I tried CreateTimeFrom and CreateTimeTo but received an Unknown property CreateTimeFrom error, so I do not believe I can use that for this request.
Anyone know how to filter date range in reports?
edit:
So it looks like startTime and endTime is apart of DownloadRequestFilter
DownloadRequestFilter DateTime
I thought something like this would work..
$datefilter = new BulkDataExchange\Types\DateFilter();
$datefilter->startTime = new DateTime('22-10-2016');
$datefilter->endTime = new DateTime('23-10-2016');
//
$startDownloadJobRequest->downloadRequestFilter->dateFilter = $datefilter;
but this doesn't work and I still get all results.
I am current using CodeIgniter 2.2.2 and I have the following code inside my modal:
$this->createDate = time();
$this->db->insert('someDB_Table', $this);
Where my createDate type is a timestamp (i also tried datetime). But this is giving me all zeros when inserting inside DB. Is there other way to get around this? Like such: 0000-00-00 00:00:00
Try this(array input method)
$my_array = array(
'database_field' => $this->input->post('input_form_field'),
'time_stamp' => date('Y-m-d H:i:s'),
);
$this->db->insert('someDB_Table', $my_array);
I fixed the error:
this->createDate = date("Y-m-d H:i:s");
Apparently Datetime/Timestamp requires a format to be recognizes in time at insertion. So here you go!
It looks like your are storing the date inside the variable "createDate" which is stored in your structure variable $this. So it is quite the same as $this['createDate'] = time();
Try to do :
$this = time();
$this->db->insert('someDB_Table', $this);
or
$this->createDate = time();
$this->db->insert('someDB_Table', $this->createDate);
I haven't tested it but both of them should work. Also check your table column name (Sometimes bugs comes from that).
Otherwise this is how I do it almost every time:
$date = time();
$mysqli->query("INSERT INTO `someDB_Table`(`createDate`) VALUES (`$date`)");
Good luck ;)
Here i got timestamp value
$user_array1[] = $val['timestamp'];
$graph_data1 ='';
if(is_array($user_array1))
{
$graph_data1 = implode(',',$user_array1);
}
Output when i print_r($graph_data1);
I got
,2014-05-26 00:43:45,2014-05-26 00:43:52,2014-05-26 00:43:592014-05-26
00:43:19,2014-05-26 00:43:24,2014-05-26 00:43:27,2014-05-26
00:43:30,2014-05-26 00:43:34,2014-05-26 00:43:37,2014-05-26
00:43:41,2014-05-26 00:43:45,2014-05-26 00:43:52,2014-05-26
00:43:59,2014-05-26 00:44:11
Highchart side :
categories: [<?php echo $graph_data1 ?> ]
it does not show any things.
In your current format of data, your string are considered malformed, and therefore incorrect for input in highcharts. You must format it correctly fist. Consider this example:
$graph_data1 = "'".implode("','", $user_array1)."'";
Should output something like this:
'2014-05-26 00:43:45','2014-05-26 00:43:45','2014-05-26 00:43:45' ... etc ...