<?php
require_once 'config.php';
//$error=false;
$errors=array();
$cities=array();
$smsflag=0;
if(isset($_GET['user_id'])){
$smsflag=$_GET['user_id'];}
$query="SELECT * FROM orders WHERE user_id=".$_GET['user_id']." ORDER BY id DESC";

$row = mysqli_query($con,$query);
     
    if (mysqli_num_rows($row) >= 1) {
		//$r=mysqli_fetch_array($row)	;
			
		 while($r=mysqli_fetch_array($row)){
			 
			/*$products=explode(",",$r['product_id']);
			foreach($products as $key=>$p){
				
				
			$cat=mysqli_fetch_array(mysqli_query($con,"SELECT * FROM products WHERE id=".$p));
			$row1 = mysqli_query($con,'SELECT * FROM product_img WHERE product_id= '.$p);
			 while($r1=mysqli_fetch_array($row1)){
				 $images[]=['id'=>$r1['id'],'image'=>$r1['image']];
			 }
			$pdata[]=['product_id'=>$r['product_id'],'name'=>$cat['name'],'itemprice'=>$cat['price'],'itemimages'=>$images]; 
		
		
			} */
			 $pdata=array();
			
			$cities[]=['orderid'=>$r['id'],'user_id'=>$r['user_id'],'product_id'=>$r['product_id'],'orderproducts'=>$pdata,'amount'=>$r['amount'],'transaction_id'=>$r['transaction_id'],'used_cashpoints'=>$r['used_cashpoints'],'use_voucherpoints'=>$r['use_voucherpoints'],'address'=>$r['address'],'city'=>$r['city'],'state'=>$r['state'],'pincode'=>$r['pincode'],'date'=>date('dS F Y',strtotime($r['date']))];
			
			
			
		}   
		$errors['orders']=$cities;
		
		$errors['success']='order history data';
    } else {
        
		$errors['success']='There is no order found';
    }
	echo json_encode($errors);
?>