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

 $query='SELECT * FROM products WHERE cate_id='.$_GET['category_id'];

$row = mysqli_query($con,$query);
     
    if (mysqli_num_rows($row) >= 1) {
		//$r=mysqli_fetch_array($row)	;
			
		 while($r=mysqli_fetch_array($row)){
			 			 $row1 = mysqli_query($con,"SELECT * FROM product_img WHERE product_id= ".$r['id']." LIMIT 1");
			 
			$r1=mysqli_fetch_array($row1);
			
			/*$row1 = mysqli_query($con,'SELECT * FROM product_img WHERE product_id= '.$r['id']);
			 while($r1=mysqli_fetch_array($row1)){
				 $images[]=['id'=>$r1['id'],'image'=>$r1['image']];
			 }*/
			
			$cities[]=['id'=>$r['id'],'name'=>$r['name'],'price'=>$r['price'],'description'=>$r['description'],'created_at'=>$r['created_at'],'product_images'=>$r1['image']];
			
		}   
		$errors['products']=$cities;
		//$errors['product_images']=$images;
		$errors['success']='products data';
    } else {
        
		$errors['success']='There is no products found';
    }
	echo json_encode($errors);
?>