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

$query='SELECT * FROM products WHERE id='.$_GET['product_id'];

$row = mysqli_query($con,$query);
     
    if (mysqli_num_rows($row) >= 1) {
		//$r=mysqli_fetch_array($row)	;
			
		 while($r=mysqli_fetch_array($row)){
			 
			 //$clear = strip_tags($r['description']);
//$clear=strip_tags(html_entity_decode($r['description']));
//$clear=filter_var($clear, FILTER_SANITIZE_STRING);
			$cities[]=['id'=>$r['id'],'name'=>$r['name'],'price'=>$r['price'],'description'=>$r['description'],'created_at'=>$r['created_at']];
			
			
			
			
		}   
		$row1 = mysqli_query($con,'SELECT * FROM product_img WHERE product_id= '.$_GET['product_id']);
			 while($r1=mysqli_fetch_array($row1)){
				 $images[]=['id'=>$r1['id'],'image'=>$r1['image']];
			 }
		$row12 = mysqli_fetch_array(mysqli_query($con,'SELECT AVG(ratting) AS Averageratings FROM product_reviews WHERE product_id= '.$_GET['product_id']));
		$errors['product_details']=$cities;
		$errors['product_images']=$images;
		$errors['product_avgratting']=$row12['Averageratings'];
		$errors['success']='products data';
    } else {
        
		$errors['success']='There is no products found';
    }
	echo json_encode($errors);
?>