<?php
error_reporting(0);
if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start("ob_gzhandler"); else ob_start();
// PDO connect *********
include_once('../config/minho.php');
function connect() { 
	$dsn = 'mysql:host=' . DB_HOST . ';dbname=' . DB_NAME;  
    return new PDO($dsn, DB_USER, DB_PASS, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
}

$pdo = connect();
$keyword = '%'.$_POST['keyword'].'%';

$sql = "(SELECT DISTINCT(FORMAT(Amount,2)) as Amount FROM buyer_cheque_monitoring WHERE Amount LIKE (:keyword)) UNION (SELECT DISTINCT(FORMAT(ReplaceAmount,2)) as Amount FROM buyer_cheque_monitoring WHERE ReplaceAmount LIKE (:keyword)) ORDER BY Amount ASC LIMIT 0, 10";
$query = $pdo->prepare($sql);
$query->bindParam(':keyword', $keyword, PDO::PARAM_STR);
$query->execute();
$list = $query->fetchAll();
foreach ($list as $rs) {
	// put in bold the written text
	$amount =  strtoupper(str_replace($_POST['keyword'], '<b>'.$_POST['keyword'].'</b>', $rs['Amount']));
	

	// add new option
    echo '<li onclick="set_item5(\''.str_replace("'", "\'", $rs['Amount']).'\')">'.$amount.'</li>';
}
?>