I want to make auto complete text box for select employee names from the database. I don\'t have fair idea about that. But I tried to make it as following.
autocomplete
// create search.php
query("SELECT * FROM employee WHERE name LIKE '%".$searchTerm."%' ORDER BY name ASC");
while ($row = $query->fetch_assoc()) {
$data[] = $row['name'];
}
//return json data
echo json_encode($data);
?>
// SQL
CREATE TABLE IF NOT EXISTS `employee` (
`id` int(11) NOT NULL,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
--
-- Dumping data for table `employee`
--
INSERT INTO `employee` (`id`, `name`) VALUES
(1, 'Ram'),
(2, 'Ravi'),
(3, 'Kumar'),
(3, 'Aaathava'),
(4, 'Sasi');
// End
Autocomplete textbox