我正在使用json autocomplete来过滤php codeigniter中数据库中的文本。我希望过滤像“Apple”这样的重复条目,“Apple”可以显示一个条目“Apple”。以下代码用于过滤
$(function() {
$( "#partnumber" ).autocomplete({
source: function(request, response) {
$.ajax({ url: base_url+"/suggest/part",
data: { term: $("#category").val(), brand: $("#brand").val(), pname: $("#partname").val(), partid: $("#partnumber").val()},
dataType: "json",
type: "POST",
success: function(data){
response(data);
}
});
},
minLength: 2
});
});
控制器
function part()
{
$term = $this->input->post('term');
$brand = $this->input->post('brand');
$pname = $this->input->post('pname');
$part = $this->input->post('partid');
$sts = 0;
if (strlen($part) < 2) break;
$rows = $this->suggest->part(array('keyword' => $part,'category' => $term, 'brand_name' => $brand,'p_name' => $pname, 'pres_sts' => $sts));
$json_array = array();
foreach ($rows as $row)
array_push($json_array, $row->part_number);
echo json_encode($json_array);
}
模型
function part($options = array())
{
$this->db->select('part_number');
$this->db->like('ctr_name', $options['category']);
$this->db->like('brn_name', $options['brand_name']);
$this->db->like('prt_name', $options['p_name']);
$this->db->like('present_status', $options['pres_sts']);
$this->db->like('part_number', $options['keyword'], 'after');
$query = $this->db->get('partnumber');
return $query->result();
}
请帮我解决这个问题。非常感谢。
答案 0 :(得分:0)
在选择$this->db->select('part_number');
$this->db->distinct();