[eluser]Unknown[/eluser]
hello, now i'm trying to make a search form using jquery autocomplete. But i got stuck in getting the value from database. here's my controller code :
Code:
<?php
class Pencarian extends Controller {
function Pencarian()
{
parent::Controller();
$this->load->database();
$this->load->helper('url');
$this->load->library('session');
$this->load->library('pagination');
$this->webconfig = $this->config->item('webconfig');
$this->load->model('ImagesModel');
}
function index()
{
$q = $this->input->post('q');
$ldata = array();
/*$items = $this->ImagesModel->listData(array()); */
/*$items = array(
"anto" => "ari", "ani" => "anto", "anti" => "arman", "anet", "arman",
"bobi", "baru", "biru", "bobo", "bunru",
);*/
$items = $this->ImagesModel->pencarianData(array('start' => 0));
foreach ($items as $key => $value) {
if (strpos(strtolower($key), $q) !== false) {
echo "$key|$value\n";
}
}
}
}
I'm trying to get the value by taking the name in the from the database and here's the model :
Code:
public function pencarianData($params=array()){
$id = isset($params["id"])?$params["id"]:'';
$start = isset($params["start"])?$params["start"]:'';
$limit = isset($params["limit"])?$params["limit"]:'';
$offsetData = "";
$conditional = "";
$rest = "ORDER by name ASC";
if($limit > 0){
if($start > 0){
$offsetData = "LIMIT ".$start.", ".$limit."";
}else{
$offsetData = "LIMIT 0, ".$limit."";
}
}
$q = $this->db->query("
SELECT
name
FROM
ina_images
".$conditional."
".$rest."
".$offsetData."
");
$result = $q->result_array();
return $result;
}
Somebody help me please with this...