<?php

if (isset($_SESSION['media-data']) && isset($_POST['apa']) && $_POST['apa'] != "") {
    include 'pelanggan/class.pelanggan.php';
    $data = new pelanggan();
    switch ($_POST['apa']) {
        case 'get-rayon':
            if (isset($_POST['area']) && $_POST['area'] != "") {
                if ($query = $data->runQuery("SELECT `id`, `rayon` FROM `rayon` WHERE `id_area` = '" . $_POST['area'] . "' AND `hapus` = '0';")) {
                    while ($rs = $query->fetch_array()) {
                        echo "<option value='" . $rs['id'] . "'>" . $rs['rayon'] . "</option>";
                    }
                }
                break;
            }
            break;
        case 'get-pelanggan':
            $collect = array();
            if (isset($_POST['area']) && $_POST['area'] != "" && isset($_POST['rayon']) && $_POST['rayon'] != "") {
                $area = $_POST['area'];
                $rayon = $_POST['rayon'];
                $qCari = "SELECT `pelanggan`.*, `area`.`area` as `nm_area`, `rayon`.`rayon` as `nm_rayon` FROM `pelanggan` \n\t\t\t\t\t\tINNER JOIN `area` ON `area`.`id`=`pelanggan`.`area` INNER JOIN `rayon` ON `rayon`.`id`=`pelanggan`.`rayon` \n\t\t\t\t\t\tWHERE `pelanggan`.`area` = '{$area}' AND `pelanggan`.`rayon` = '{$rayon}' AND `pelanggan`.`hapus`= '0' ORDER BY `pelanggan`.`id` DESC ";
                if ($query = $data->runQuery($qCari)) {
                    while ($rs = $query->fetch_array()) {
                        $detail = array();
                        array_push($detail, $rs["noreg"]);
                        array_push($detail, stripslashes($rs["nama"]));
                        array_push($detail, stripslashes($rs["alamat"]));
                        array_push($detail, stripslashes($rs["nm_rayon"]));
                        array_push($detail, stripslashes($rs["pasar"]));
                        array_push($detail, stripslashes($rs["sub_pasar"]));
<?php

if (isset($_POST['cari']) && $_POST['cari'] != "" && isset($_POST['area']) && $_POST['area'] != "") {
    include 'pelanggan/class.pelanggan.php';
    $data = new pelanggan();
    if ($daftar = $data->daftar_pelanggan_by_area($_POST['cari'], $_POST['area'])) {
        while ($rs = $daftar->fetch_array()) {
            echo "<option value='" . $rs['id'] . "'>[" . $rs['noreg'] . "] " . stripslashes($rs['nama']) . ", " . $rs['alamat'] . " " . $rs['nm_area'] . "</option>";
        }
    }
}