<?php
include_once('conn.php');

$cust_id = $_GET['q'];

$sqli="SELECT SUM(bill_amount - paid) as `arear1` FROM `c_bill` where c_id=$cust_id";
if ($resulti=mysqli_query($con,$sqli)){ 
while($rowi = $resulti->fetch_assoc()) { 
$arear1 = $rowi['arear1'];
 }}
$sql="SELECT * FROM `c_bill` where c_id=$cust_id ORDER BY c_id DESC LIMIT 1" ;
if ($result=mysqli_query($con,$sql)){ 
while($row = $result->fetch_assoc()) { 
$inv = $row['c_inv'];
$pkg = $row['pkg_id'];
$arear = $row['arear'];
$bill = $row['bill_amount'];
$total = $row['total_amount'];
$date = $row['due_date'];
$month = $row['bill_month'];
$paid = $row['paid'];
  }}

$data = array();

		$name["inv"] =$inv ;
		$name["pkg"] =$pkg ;
		$name["arear"] =$arear ;
		$name["arear1"] =$arear1 ;
		$name["bill"] =$bill ;
		$name["total"] =$total ;
		$name["date"] =$date;
		$name["month"] =$month;
		$name["paid"] =$paid;
	           array_push($data, $name);   

//return json data
echo json_encode($data);

?>