<?php
	include "dbconnect.php";
	/* $dateran = '20/12/2017 - 27/12/2017';
	
	$date = explode('-', $dateran);
	$fst_date = trim($date[0], " ");
	$expdate1 = explode('/', $fst_date);
	$ftdate = new DateTime($expdate1[2]."-".$expdate1[1]."-".$expdate1[0]);
	$fdate = $ftdate->format("Y-m-d");
	$fst_mnth = date('d M Y',strtotime($fdate));

	$lst_date = trim($date[1], " ");
	$expdate2 = explode('/', $lst_date);
	$ltdate = new DateTime($expdate2[2]."-".$expdate2[1]."-".$expdate2[0]);
	$ldate = $ltdate->format("Y-m-d");
	$last_mnth = date('d M Y',strtotime($ldate));

	$mnth_yr = $fst_mnth." - ".$last_mnth;

	$days = date('d-m-Y',strtotime($ldate))-date('d-m-Y',strtotime($fdate));
	for ($i=0; $i < $days+1; $i++) { 
		echo $fdate = $ftdate->format("Y-m-d")."<br>";
		$ftdate->modify("1 day");
	} */
	
	$client_id = '91';
	//$date = date('Y-m-d');
	$date = date('d');
	$mname = date('m');
	$cryear = date('Y');
	$total_days = cal_days_in_month(CAL_GREGORIAN, $mname, $cryear);
	
	$crdate = array();
	$respond = array();
	
	for($i = 1; $i <= $total_days; $i++) {
		$startdate = $cryear."-".$mname."-".$i;
		$enddate = date('Y-m-d');
		$qry = mysql_query("SELECT DISTINCT(`sale_date`) AS saledate FROM `feedback_response` WHERE `sale_date` >= '$startdate' AND `client_id` = '$client_id'");
		while($row = mysql_fetch_array($qry)) {
			$fdate = $row['saledate'];
			$frd_qry = mysql_query("SELECT (SUM(  frd.`ans_wt` ) / COUNT( DISTINCT(frd.`fb_no`) )) AS avg FROM `feedback_response_details` as frd RIGHT JOIN `feedback_response` as fbr ON frd.`fb_no` = fbr.`fb_no` AND fbr.`sale_date` >= '$fdate' AND frd.`fb_ques_id` = '1'");
			$respond[] = $frd_row['avg'];
		}
		
		
		
		
		echo "<pre>";
		print_r($respond);
		//$crdate[] = date('d M', strtotime($startdate));
		// echo "<pre>";
		// print_r($crdate);
	}

?>