This is the first time I post a question here, because usually I can find the answer in the questions asked before, this time thought I can't figure it out on my own, so I am counting on your help.
The thing is I use the jQuery autocomplete widget to get information from my database, with a request to get all the hotels name from a hotel table, I'm sure I get all the hotels, but the autocomplete seems not to work with some of them, for example I have 5 hotels : batchmor, sofitel drive, sofitel bartimela, marselle, Juliana. When I press 'b', batchmor and sofitel bartimela will appear, but when I press 's' neither sofitel driver or sofitel bartimela will appear and I don't know the source of the error.
I drop here the jQuery code I use for calling the external PHP file:
//javascript code
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/themes/base/minified/jquery-ui.min.css" type="text/css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.1/jquery-ui.min.js"></script>
</head>
<body>
<form>
<input type="text" id="recherche" />
</form>
<script type="text/javascript">
$('#recherche').autocomplete({
source : 'cnxtobase.php'
});
</script>
</body>
and there is the code that's in the cnxtobase.php file
if(isset($_GET['term'])){
$array = array();
}
try{
$conn = new PDO('mysql:host=localhost;dbname=Lodging','root','');
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare('SELECT name FROM hotel WHERE name LIKE:term');
$stmt->execute(array(':term' =>'%'.$_GET['term'].'%'));
foreach ($stmt->fetchAll() as $value) {
array_push($array, $value['name']);
}
}catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
echo json_encode($array);
and my database I have
When I use the autocomplete with the letter 'B' or 'ba' I'll get bachaumont but also sofitel baltimor but when I type 'S' I won't get sofitel baltimor, good to know that I add a hotel named soufitel and when I type 'SO' nothing appear but when I type 'sou' soufitel appears.