i am trying for autocomplete ajax script for listing category and its subcategory
public function ajax($term,$locale = 'en_US')
{
if($locale == null) {
return false;
}
$this->dao->select( "ct.*,dt.s_name");
$this->dao->from($this->getTableName().' ct, '.DB_TABLE_PREFIX.'t_category_description dt');
$this->dao->where( 'dt.fk_c_locale_code', $locale );
$this->dao->where('ct.pk_i_id = dt.fk_i_category_id');
$this->dao->like('dt.s_name', $term, 'after');
$result = $this->dao->get();
$g = $result->result();
$r = array();
foreach ($g as $key=>$val){
if($val['fk_i_parent_id']){
$this->dao->select( "s_name");
$this->dao->from( $this->getTablePrefix() . 't_category_description' );
$this->dao->where( 'fk_i_category_id', $val['fk_i_parent_id']);
$this->dao->where( 'fk_c_locale_code', $locale );
$result = $this->dao->get();
$s = $result->result();
$r[$key]['id'] = $val['pk_i_id'];
$r[$key]['label'] = $s[0]['s_name'].' › '.$val['s_name'];
$r[$key]['value'] = strtolower($s[0]['s_name']);
}else{
$r[$key]['id'] = $val['pk_i_id'];
$r[$key]['label'] = $val['s_name'];
$r[$key]['value'] = strtolower($val['s_name']);
}
}
return $r;
}
this function will be called when i type a keyword and $term = keyword here...
this function is working perfect for me now, but i need to reduce all into single query.
you can understand what i am doing inside the functions and what i need.
i hope i will get help soon, thanks .