<?php
require_once 'config.php';
//$error=false;
$errors=array();
$cities=array();

$query='SELECT * FROM orders WHERE id='.$_GET['order_id'];

$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']];
			 }*/
			 $cat=mysqli_fetch_array(mysqli_query($con,"SELECT products.*,product_img.* FROM products LEFT JOIN product_img ON products.id = product_img.product_id WHERE products.id=".$p));
			
			$row1 = mysqli_query($con,'SELECT * FROM product_img WHERE product_id= '.$r['product_id']);
			 while($r1=mysqli_fetch_array($row1)){
				 $images[]=['id'=>$r1['id'],'image'=>$r1['image']];
			 }
			$pdata[]=['itemid'=>$r['id'],'user_id'=>$r['user_id'],'product_id'=>$r['product_id'],'name'=>$cat['name'],'itemprice'=>$cat['price'],'itemimages'=>$cat['image'],'status'=>$r['status']]; 
		
		
			}
			$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'],'unit_no'=>$r['unit_no'],'floor'=>$r['floor'],'city'=>$r['city'],'state'=>$r['state'],'country'=>$r['country'],'pincode'=>$r['pincode'],'discount_type'=>$r['discount_type'],'coupon_id'=>$r['coupon_id'],'price_reduce_by_coupon'=>$r['price_reduce_by_coupon'],'cart_price'=>$r['cart_price'],
			'shipping_charge'=>$r['shipping_charge'],'date'=>date('dS F Y',strtotime($r['date']))];
			
			
			
		}   
		$errors['orders']=$cities;
		
		$errors['status']=true;
		
		$errors['message']='order details data';
    } else {
        $errors['status']=false;
		$errors['message']='There is no order found';
    }
	echo json_encode($errors);
?>