<?php
if(file_exists('../../../../'.$_REQUEST['tenant'].'/config.php')) {
    require_once('../../../../'.$_REQUEST['tenant'].'/config.php');
}
if(file_exists('/config.php')) {
    require_once('/config.php');
}

header('Content-Type: application/json');

$out = [];
$sql = "SELECT clientnumber, clientname, postcode FROM clientdetails WHERE statuslive = 1 ORDER BY clientname ASC";
$res = $con->query($sql);

if ($res) {
    while ($row = $res->fetch_assoc()) {
        $out[] = [
            'clientnumber' => $row['clientnumber'],
            'company' => $row['clientname'],
            'postcode' => $row['postcode']
        ];
    }
    echo json_encode($out);
} else {
    echo json_encode(['error' => true, 'message' => $con->error]);
}