<?php
include "../../../../wp-blog-header.php";

$keyword = trim($_POST['keyword']);
$limit = 10;
$page_no = isset($_POST['page_no'])?$_POST['page_no']:1;
$offset = ($page_no-1)*$limit;

//pr($_POST);

global $wpdb,
$hotels_tbl,
$destinations_tbl,
$countries_tbl;

$sql = '';
$sql2 = '';

$sql .= "SELECT DISTINCT(`hotel_search`) FROM `$hotels_tbl` USE INDEX (index_hotel_search)";
$sql2 .= "SELECT DISTINCT(`destination_search`) FROM `$hotels_tbl` USE INDEX (index_destination_search)";

if(!empty($keyword)){
    $sql .= " WHERE `hotel_search` LIKE '%".$keyword."%' ";

    $sql2 .= " WHERE `destination_search` LIKE '%".$keyword."%' ";
}

$sql .= "LIMIT ".$offset .",".$limit;

$sql2 .= "LIMIT ".$offset .",".$limit;

//pr($sql);
//pr($sql2);


if(!empty($keyword)) {
	$results = $wpdb->get_results($sql);
	$results2 = $wpdb->get_results($sql2);

  //print_r($results);

	$data = array(
		'hotels' => $results,
		'destinations' => $results2
	);

	die(json_encode($data));

}
 