<?php
include '../koneksi.php';

$keyword = $_POST['pic'];
$idcustomer = $_POST['idcustomer'] ?? '';
// $cari = mysqli_query($konek, "SELECT * FROM pic WHERE nama_pic = '$keyword'");
// $datasd = mysqli_fetch_assoc($cari);
// $idcustomer = $datasd["idcustomer"];

$query = mysqli_query($konek, "
    SELECT *
    FROM picb
    WHERE nama_pic LIKE '%$keyword%' and idcustomer='$idcustomer'
    LIMIT 5
");

if (mysqli_num_rows($query) > 0) {
    while ($row = mysqli_fetch_assoc($query)) {
        $pic = str_replace(
            ['Bapak ', 'Ibu '], 
            '', 
            $row['nama_pic']
        );
        echo '<div class="list-group-item pic-item"
                data-id="' . $row['idpic'] . '" 
                data-telep="' . $row['telp_pic'] . '" 
                data-note="' . $row['note'] . '" 
                data-nama="' . $pic . '">
                ' . $row['nama_pic'] .
            '</div>';
    }
}
