Create REST API
Posted: Thu Feb 25, 2021 4:32 pm
QNS
I'm having an issue so l managed to answer the first part of just creating an API that returns the data in JSON format but now I'm confused with the last part that is below where l need to add sessionID if the user is logged out.
Create an api that return the SessionID,storeID and ChannelCode where
outTS column is 0000-00-00 00:00:0
Second part of the Qns
After that add the sessionID when the user is log off(0000-00-00 00:00:00) to the api
I'm having an issue so l managed to answer the first part of just creating an API that returns the data in JSON format but now I'm confused with the last part that is below where l need to add sessionID if the user is logged out.
Create an api that return the SessionID,storeID and ChannelCode where
outTS column is 0000-00-00 00:00:0
Code: Select all
<?php
// displaying errors faced
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// call the database file
include('includes/db.inc.php');
//response
$response = array();
// select the data from the table checkinSession
$sql_query = "SELECT sessionID, storeID, channelCode FROM checkinSession WHERE outTS = '0000-00-00 00:00:00'";
$sql_data = mysqli_query($con, $sql_query);
// fetching data as an associative array
if($sql_data){
$i = 0;
while($sql_data_arr = mysqli_fetch_assoc($sql_data)){
$response[$i]['sessionID'] = $sql_data_arr['sessionID'];
$response[$i]['storeID'] = $sql_data_arr['storeID'];
$response[$i]['channelCode'] = $sql_data_arr['channelCode'];
$i++;
};
// OUTPUT DATA (JSON)
header("Content-Type: application/json");
echo json_encode($response, JSON_PRETTY_PRINT);
}
else{
// OUTPUT DATA (JSON)
header("Content-Type: application/json");
echo json_encode("nothing returned", JSON_PRETTY_PRINT);
}
?>
Second part of the Qns
After that add the sessionID when the user is log off(0000-00-00 00:00:00) to the api