<?php 

class DbOperations 
{
	
	private $con;

	function __construct(){
		// require_once dirname(__FILE__).'../DbConnects.php';
		require_once "../includes/DbConnects.php";

		$db = new DbConnect();
		$this -> con = $db -> connect();
	}


public function getOrdersByUsername($username){
		$stmt = $this -> con -> prepare("SELECT id,orders,user,day,update_time from orders_made_tb where status ='N' and user='$username' ORDER BY ID,USER,DAY ASC");
		$stmt -> execute();
$stmt -> bind_result($id,$meals,$user,$day,$update_time);
$orderCall = array();

// traversing through all the result 
 while($stmt->fetch()){
 $temp = array();
 $temp['id'] = $id;
 $temp['orders'] = $meals;
 $temp['user'] = $user;
 $temp['day'] = $day;
 $temp['update_time'] = $update_time; 
 array_push($orderCall, $temp);
 }
//  // print_r($orderCall); echo "<br/><br/>";
//  //displaying the result in json format 
echo json_encode($orderCall);
		

		
	}
}	
	

	$response = array();

if($_SERVER['REQUEST_METHOD'] == 'POST'){

	if(isset($_POST['username'])){
		$db = new DbOperations();

		$username = $_POST['username'];
	

			$user = $db->getOrdersByUsername($username);


			// $response['error'] = false;
			// $response['id'] = $user['id'];
			// $response['orders'] = $user['orders'];
			// $response['user'] = $user['user'];
			// $response['day'] = $user['day'];
			// $response['update_time'] = $user['update_time'];

}else{
	echo "Invalid Request";
}
header('Content-Type: application/json');
// echo json_encode($response);
 }