<?php

require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include ('includes/function.php');

$zdb = $_SESSION["zdbyear_" . $dbname];
mysqli_select_db($conn, $zdb);
$admin = $_SESSION["admin_" . $dbname];
$success = false;

$custname = $_REQUEST['custname'];

$cond = "";
if (!empty($custname)) {
    $cond = " AND `name` LIKE '%$custname%'";
}

$query = "SELECT `accode`,`name`,`city`,`mobile`,`station`,`pin`,`tel`,discount,packing,paid FROM `accmast` WHERE `grpcode`='010' $cond ORDER BY `name`";

$result = mysqli_query($conn, $query)or die(mysqli_error($conn));

$rows = array();
$ctr = 0;
while ($r = mysqli_fetch_assoc($result)) {
    $rows[] = [ 'success' => true,
                'ctr' => $ctr,
                'accode' => $r['accode'],
                'name' => $r['name'],
                'city' => $r['city'],
                'station' => $r['station'],
                'pin' => $r['pin'],
                'tel' => $r['tel'],
                'discount' => $r['discount'],
                'packing' => $r['packing'],
                'paid' => $r['paid'],
                'mobile' => $r['mobile']
    ];
    $ctr++;
}
header("Content-type: application\json");
echo json_encode($rows);

