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

mysqli_query($con,'DELETE FROM cart_items WHERE id='.$_GET['item_id']);

$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 * FROM products WHERE 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'],'itemprice'=>$cat['price'],'itemimages'=>$images,'status'=>$r['status']];
			$totalcart=$totalcart+$cat['price'];
			
		}   
		$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);
?>