Help me, i wanna put the timestone to this format Hour:minutes:secondes
$services = $pdo ->prepare("SELECT * FROM `servicos` WHERE `DE` = :u");
$services->bindValue(":u", "1");
$services->execute();
echo $numServico = $services->rowCount(); // Contagem de serviços
$l = $services->fetchAll(PDO::FETCH_OBJ);
//$json = json_encode($l);
echo '{"data":[';
//echo $json;
foreach ($l as $listar) {
$inicioHora = new DateTime("listar->REGISTRO");
$inicioHora = $inicioHora->format('H:i:s');
}
But i receive this
Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): Failed to parse time string (listar->REGISTRO) at position 0 (l): The timezone could not be found in the database' on line 26
if the field $listar->REGISTRO is a timestamp, then you only need to use the date() function http://php.net/manual/en/function.date.php
$time = date('H:i:s', $listar->REGISTRO);
Replace this:
$inicioHora = new DateTime("listar->REGISTRO");
$inicioHora = $inicioHora->format('H:i:s');
With this:
$inicioHora = date('H:i:s', strtotime($listar->REGISTRO));
Related
Currently, I created a system that uses daypilot calendar. For example, when I clicked a date, it will show the list of activities on that selected date.
Below code is successful display the list:
<?php
require_once '../../../config/configPDO.php';
$Fac_ID = strtolower($_GET['Fac_ID']);
$Room_Desc = strtolower($_GET['Room_Desc']);
$stmt = $conn->prepare("SELECT * FROM booking LEFT JOIN room ON booking.Room_ID = room.Room_ID
WHERE room.Fac_ID = '$Fac_ID' AND room.Room_Desc = '$Room_Desc' AND Book_Status <> 'Reject'");
$stmt->execute();
$result = $stmt->fetchAll();
class Event {}
$events = array();
foreach($result as $row) {
$e = new Event();
$e->id = $row['Book_No'];
$e->text = "Meeting Name: ". $row['Meeting_Description']. " || " ."Requested by: ".$row['Requested_by']. " || " ."Location: ".$row['Fac_ID']. ", " .$row['Room_Desc'];
$e->start = $row['StartTime'];
$e->end = $row['EndTime'];
$events[] = $e;
}
header('Content-Type: application/json');
echo json_encode($events);
?>
But, when I change the code (Because want to retrieve json data), the data doesn't display at calendar.
Below is the code:
<?php
require_once '../../../config/configPDO.php';
$Fac_ID = strtolower($_GET['Fac_ID']);
$Room_Desc = strtolower($_GET['Room_Desc']);
//retrieve json
$url = "http://172.20.0.45/TGWebService/TGWebService.asmx/displayPABooking?Fac_ID=$Fac_ID&Room_Desc=$Room_Desc&Room_ID=&Book_No=&Book_Date_From=&Book_Date_To=";
$data = file_get_contents($url); //line 10
$json = json_decode($data);
$result = $json->bookingList; //line 12
class Event {}
$events = array(); //
foreach($result as $row) { //line 17
$e = new Event();
$e->id = $row->bookNo;
$e->text = "Meeting Name: ".$row->desc. " || " ."Requested by: ".$row->requestedBy." || " ."Location: ".$row->facID.", " .$row->roomName;
$e->start = $row->startTime;
$e->end = $row->endTime;
$events[] = $e;
}
header('Content-Type: application/json');
echo json_encode($events);
?>
And, This is the error that I found at console:
PHP Warning: file_get_contents(http://172.20.0.45/TGWebService/TGWebService.asmx/displayPABooking?Fac_ID=TGT&Room_Desc=LEVEL 1 &Room_ID=&Book_No=&Book_Date_From=&Book_Date_To=): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request
in C:\inetpub\wwwroot\ebooking\pages\manual_booking\backend\backend_events.php on line 10
PHP Notice: Trying to get property 'bookingList' of non-object in C:\inetpub\wwwroot\ebooking\pages\manual_booking\backend\backend_events.php on line 12
PHP Warning: Invalid argument supplied for foreach() in C:\inetpub\wwwroot\ebooking\pages\manual_booking\backend\backend_events.php on line 17
Can I know where I need to change? Thanks
This is probably because of the space in "Level 1". Try urlencoding your $_GET parameters:
$url = "http://172.20.0.45/TGWebService/TGWebService.asmx/displayPABooking?Fac_ID=" . urlencode($Fac_ID) . "&Room_Desc=" . urlencode($Room_Desc) . "&Room_ID=&Book_No=&Book_Date_From=&Book_Date_To=";
If you want to make the variable substitution more explicit, you could use strtr:
$template = "http://172.20.0.45/TGWebService/TGWebService.asmx/displayPABooking?Fac_ID={Fac_ID}&Room_Desc={Room_Desc}&Room_ID=&Book_No=&Book_Date_From=&Book_Date_To=";
$url = strtr($template, array(
'{Fac_ID}' => $Fac_ID,
'{Room_Desc}' => $Room_Desc
));
I am unable to export my mysql table to XML format using PHP, I receive the following error when I run the below script. I have removed the connection bit, I have gone through already errors but was not able resolve this issue.
Catchable fatal error: Argument 1 passed to DOMNode::appendChild() must be an instance of DOMNode, null given,
Script:
<?php
$query = "SELECT id, name, plate, datetime , time , image_name FROM EarlsdonMSIN_anpr_vega";
$camArray = array();
if ($result = $mysqli->query($query)) {
/* fetch associative array */
while ($row = $result->fetch_assoc()) {
array_push($camArray, $row);
}
if(count($camArray)){
createXMLfile($camArray);
}
/* free result set */
$result->free();
}
/* close connection */
$mysqli->close();
function createXMLfile($camArray){
$filePath = '/cam.xml';
$dom = new DOMDocument('1.0', 'utf-8');
$root = $dom->createElement('cam');
for($i=0; $i<count($camArray); $i++){
$camId = $camArray[$i]['id'];
$camName = $camArray[$i]['name'];
$camplate = $camArray[$i]['plate'];
$camdatetime = $camArray[$i]['datetime'];
$camtime = $camArray[$i]['time'];
$camimagename = $camArray[$i]['image_name'];
$cam = $dom->createElement('cam');
$cam->setAttribute('id', $camId);
$name = $dom->createElement('name', camName);
$cam->appendChild($name);
$plate = $dom->createElement('plate', $camplate);
$cam->appendChild($plate);
$datetime = $dom->createElement('datetime', $camdatetime);
$cam->appendChild($datetime);
$time = $dom->createElement('time', $camtime);
$cam->appendChild($time);
$imagename = $dom->createElement('image_name', $camimagename); $cam->appendChild($image_name);
$root->appendChild($cam);
}
$dom->appendChild($root);
$dom->save($filePath);
}
I am trying to use SoapClient in PHP to retrieve data from a WSDL. If I use hardcoded values, then it works with zero errors:
$client = new SoapClient(someWSDLUrl);
$params2 = array();
$params2['AuthenticationKey'] = $obj->{'LoginResult'};
$params2['VehicleClass'] = 'UsedCar';
$params2['ApplicationCategory'] = 'Consumer';
$params2['VersionDate'] = '2016';
$result2 = $client->GetMakes($params2);
I am getting the following error when I use variables or dynamic content:
Fatal error: Uncaught SoapFault exception: [a:DeserializationFailed
] The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter
http://someURL/VehicleInformationService:VehicleClass
. The InnerException message was 'Invalid enum value 'UsedCars'
I have tried
$client = new SoapClient(someWSDLUrl);
$params2 = array();
$params2['AuthenticationKey'] = $obj->{'LoginResult'};
$params2['VehicleClass'] = $VehicleClass;
$params2['ApplicationCategory'] = $ApplicationCategory;
$params2['VersionDate'] = $VersionDate;
$result2 = $client->GetMakes($params2);
I have also tried
$client = new SoapClient(someWSDLUrl);
$params2 = array();
$params2['AuthenticationKey'] = (string) $obj->{'LoginResult'};
$params2['VehicleClass'] = (string) $VehicleClass;
$params2['ApplicationCategory'] = (string) $ApplicationCategory;
$params2['VersionDate'] = (string) $VersionDate;
$result2 = $client->GetMakes($params2);
I have also tried:
$SubmitData = new stdClass();
$SubmitData->AuthenticationKey = new SoapVar($obj->{'LoginResult'}, XSD_STRING);
$SubmitData->VehicleClass = new SoapVar($VehicleClass, XSD_STRING);
$SubmitData->ApplicationCategory = new SoapVar($ApplicationCategory, XSD_STRING);
$SubmitData->VersionDate = new SoapVar($VersionDate, XSD_STRING);
$result2 = $client->GetMakes($SubmitData);
Same error each time. I do not know how to get around "Invalid enum value" error
Thanks in advance
I am trying to remove a tab character from a json_encoded data from php? Every time I try to fetch data from the script as JSON enocded format I use the following code below to parse my data but can not get the jsonStr to be parsed.
The error I am getting is
Error: JSON.parse: unexpected character at line 1 column 1 of the JSON
data
Code
jsonStr = data.toString();
jsonStr = JSON.stringify(jsonStr.replace("\t",""));
totJSON = JSON.parse(jsonStr['totalActionItems']);
How do I resolve this error to parse a well formed json string correctly?
EDIT
Corrected Parsing Code (JS)
$.ajax({url: "/dashboard/chartdata.php?chart=buildup", success: function(data)
{
jsonStr = data.replace(/\t/g, "");
console.log(jsonStr);
json = JSON.parse(jsonStr);
totJSON = json['totalActionItems'];
PHP Code
function getData($field, $rows)
{
$minDate = $rows[0][$field];
$maxDate = $rows[count($rows)-1][$field];
$date = $minDate;
$findDate = $minDate;
$idx = 0;
$tot = 0;
$dates = array();
$numActionItems = array();
while ($date < $maxDate)
{
if ($rows[$idx][$field] == $date)
{
$tot += $rows[$idx]['numactionitems'];
$idx++;
}
$timestamp = strtotime($date);
$date = date('Y-m-d', strtotime($date . "+1 days"));
$numActionItems[] = array('x'=>$timestamp*1000, 'y'=>$tot);
}
return $numActionItems;
}
function getBuildUpData($field)
{
$manageCharts = new manageCharts();
$rows = $manageCharts->buildup($field);
$items = getData($field, $rows);
return $items;
}
if (isset($_GET['chart']) && $_GET['chart'] == 'buildup')
{
$json = json_encode(['totalActionItems' => getBuildUpData('assigneddate'),
'ecdItems' => getBuildUpData('ecd'),
'originalDueItems' => getbuildUpData('duedate'),
'closedItems' => getBuildUpData('closeddate')]);
echo $json;
}
The following code helped produce the correct json for processing.
jsonStr = data.replace(/\t/g, "");
//console.log(jsonStr);
json = JSON.parse(jsonStr);
totJSON = json['totalActionItems'];
I am trying to do a query onto my database with the following code.
public function getFreeFields($date){
print_r($date);
$db = Zend_Registry::get('db');
$select = $db->select()
->from(array('f' => $this->_tablename()), array('f.fie_id','f.fie_name'))
->join('reservation','reservation.res_field = f.fie_id')
->where('reservation.res_date_from > ?'. $date)
->where('reservation.res_date_till < ?'. $date);
$result = $db->fetchRow($select);
$data = $this->_mapper->toObject( is_array($result) ? $result : array() );
return $data;
}
But it crashes with the following error.
Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: no parameters were bound'
When I die after the print_r, I got the correct date that I give to the request.
Any help?
change this
->where('r.res_date_from > ?'. $date)
->where('r.res_date_till < ?'. $date);
to
->where('r.res_date_from > ?', $date)
->where('r.res_date_till < ?', $date);