<?php
//Ajax Init
include "ajax-init.php";

if(isset($_GET['q'])){

    $search = strip_tags(trim($_GET['q']));


    $q = mysqli_query($dbc,"SELECT * FROM cc_card_tbl WHERE cardNumber LIKE '%$search%' AND status = 'WAITING'");

    if(mysqli_num_rows($q)){
        $data = array();
        while($rows = mysqli_fetch_assoc($q)){
            $customerData = get_customer_by_id($dbc,$rows['customerID']);
            $data[] = array(
                'id' => $rows['waiting_id'],
                'text' => $rows['cardNumber']." ".$customerData['fullName'].' ('.$customerData['phoneNum'].')'
            );
        }

        header('Content-type: application/json');
        echo json_encode($data);
        mysqli_close($dbc);
    }

}