i like to have auto complete search function in my website. There is a page on website that has search filters. When a user lands on this page all the record of users are shown in table format on that page. There is an input box that filters out the result. for example, if i type player, the table may look like below.
ID Player
1 player win
2 player win
3 player win
Please tell me how to do that?this is what my code looks like at the moment...
View:
<html>
<title></title>
<head>
<!-- Jquery Packages -->
<link type="text/css" rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css "/>
<script type="text/javascript" src="//code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript" src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<!-- Jquery Package End -->
<script type="text/javascript">
$('#txtinput').autocomplete({
source: source: "<?php echo site_url('record/index/?'); ?>"
});
</script>
</head>
<body>
<!-- Your Input Text Box-->
<input type="text" id="txtinput" size="20" />
</body>
</html>
controller :
public function index(){
$this->load->helper('url');
$this->load->helper('html');
$this->load->library('javascript');
$this->load->library('javascript/Jquery');
$this->load->view('record_view');
$this->load->model('record_model');
if (isset($_GET['term'])){
$result = $this->record_model->getData($_GET['term']);
if (count($result) > 0){
foreach ($result as $key ) {
$abc[] = $key->result;
}
echo json_encode($abc);
}
}
}
Model:
public function getData($result)
{
$this->db->like('result', $result, 'both' );
return $this->db->get('history')->result();
}