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

$query='SELECT * FROM cart_items WHERE user_id='.$_GET['user_id'];

$row = mysqli_query($con,$query);
     
    if (mysqli_num_rows($row) >= 1) {
		//$r=mysqli_fetch_array($row)	;
		$totalcart=0;
		 while($r=mysqli_fetch_array($row)){
			
			
			$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=".$r['product_id']));
			
			$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']];
			 }
			$cities[]=['itemid'=>$r['id'],'user_id'=>$r['user_id'],'product_id'=>$r['product_id'],'name'=>$cat['name'],'quantity'=>$r['quantity'],'itemprice'=>$cat['price'],
			'itemimages'=>$cat['image'],'status'=>$r['status']];
			$totalcart=$totalcart+($cat['price']*$r['quantity']);
			
		}   
		$errors['cartitems']=$cities;
		$errors['carttotal']=$totalcart;
		$errors['cartitemscount']=mysqli_num_rows($row);
		$errors['success']='cartitems data';
    } else {
        
		$errors['success']='There is no item found';
    }
	echo json_encode($errors);
?>