<?php
include("config2.php");

$search = $conn->real_escape_string($_POST['search']);

$sql = "SELECT * FROM customer WHERE nid LIKE '%$search%' or personal_phn LIKE '%$search%'  or 	customer_name LIKE '%$search%' LIMIT 10";
$result = $conn->query($sql);

if ($result->num_rows == 0) {
    echo "<div style='padding:8px;'>No results...</div>";
    exit;
}

while ($row = $result->fetch_assoc()) {

    // JSON encode for sending full record in HTML attribute
    $customer_json = htmlspecialchars(json_encode($row), ENT_QUOTES, 'UTF-8');

    echo "
    <div class='suggest-item' data-customer='$customer_json'>
        {$row['nid']} — {$row['personal_phn']} — {$row['customer_name']}
    </div>
    ";
}
?>
