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

$query=' SELECT product_reviews.*,users.* FROM product_reviews LEFT JOIN users ON product_reviews.user_id = users.id WHERE product_reviews.product_id='.$_GET['product_id'];

$row = mysqli_query($con,$query);
     
    if (mysqli_num_rows($row) >= 1) {
		//$r=mysqli_fetch_array($row)	;
		$totalcart=0;
		$i=1;
		 while($r=mysqli_fetch_array($row)){
			
			
			
			$cities[]=['itemid'=>$r['id'],'user_id'=>$r['user_id'],
			'first_name'=>$r['first_name'],'last_name'=>$r['last_name'],'email'=>$r['email'],'product_id'=>$r['product_id'],'ratings'=>$r['ratting'],'review'=>$r['reviews'],'status'=>$r['status']];
			
			$totalcart=$totalcart+$r['ratings'];
			$i++;
		}   
		$errors['rattings']=$cities;
		$errors['avgrattings']=round($totalcart/$i,1);
		
		$errors['success']='ratting data';
    } else {
        
		$errors['success']='There is no ratting found';
    }
	echo json_encode($errors);
?>