escape_string(urldecode(trim($_POST['inputSearchVal']))); } else { exit(); } // query to database if ($_POST['type'] == 'author') { $data_q = $dbs->query("SELECT author_name FROM mst_author WHERE author_name LIKE '%$searchVal%' LIMIT 5"); } else { $data_q = $dbs->query("SELECT topic FROM mst_topic WHERE topic LIKE '%$searchVal%' LIMIT 5"); } if ($data_q->num_rows < 1) { exit(); } $json_array = array(); // loop data while ($data_d = $data_q->fetch_row()) { $json_array[] = $data_d[0]; } // encode to JSON array if (!function_exists('json_encode')) { die(); } echo json_encode($json_array);