<?php 
	include "db_connection/db_connection.php";
	include "config/config.php";
	$narr = array();
	$SLCT = "SELECT party_det_id,sel_date FROM design_sel_det GROUP BY party_det_id,sel_date ORDER BY design_sel_det_id DESC";
	$QURY = mysqli_query($connect,$SLCT);
	$i=1;
	$norec = mysqli_num_rows($QURY);
	while($FTCH = mysqli_fetch_object($QURY)){
		$SLCT_dd = "SELECT COUNT(design_sel_det_id) AS sel_cnt,IFNULL(SUM(master_pieces),0) AS mas_pic FROM design_sel_det,design_det WHERE  party_det_id = '$FTCH->party_det_id' and `sel_date` ='$FTCH->sel_date' AND design_det.design_det_id = design_sel_det.design_det_id GROUP BY sel_date";
		$QURY_dd = mysqli_query($connect,$SLCT_dd);
		$FTCH_dd = mysqli_fetch_object($QURY_dd);

		$SLCT_Ec = "SELECT COUNT(design_sel_det_id) AS des_cnt,IFNULL(SUM(master_pieces),0) AS mas_pic FROM design_sel_det,design_det WHERE party_det_id = '$FTCH->party_det_id' AND design_det.design_det_id = design_sel_det.design_det_id AND ord_status = 'yes' and `sel_date` ='$FTCH->sel_date'";
		$QURY_Ec = mysqli_query($connect,$SLCT_Ec);
		$FTCH_Ec = mysqli_fetch_object($QURY_Ec);

		$SLCT_E = "SELECT cmp_name,party_code FROM party_det WHERE party_det_id = '$FTCH->party_det_id'"; 
		$QURY_E = mysqli_query($connect,$SLCT_E);
		$FTCH_E = mysqli_fetch_object($QURY_E);
		$narr[] = array($i,$FTCH_E->party_code,$FTCH_E->cmp_name,str_replace("-","/",$FTCH->sel_date),$FTCH_dd->sel_cnt,$FTCH_dd->mas_pic,'','','','');
		$i++;
	}

	/*echo "<prE>";
	print_r($narr);
	echo "<prE>";
	print_r($cars);*/

/*$cars = array (
  array("Volvo",22,18,1,1,1),
  array("BMW",15,13,1,1,1),
  array("Saab",5,2,1,1,1),
  array("Land Rover",17,15,1,1,1)
);*/

$output = array(
  "draw"=> 1,
  "recordsTotal"=>'25',
  "recordsFiltered"=>  $norec,
  "data"=>$narr
      /*"0" =>'aaaaaa',
      "1"   =>'bbbbbb',
      "2"   =>'ccccccc',
      "3"   =>'dddddd',
	  "4"   =>'eeeeee',"5" =>'ffffff',"6" =>'gggggg')*/
    );
    echo json_encode($output);
?>
