[eluser]Bigil Michael[/eluser]
Quote:function get_ordinary_search($search, $category)
{
if($search!='all'){
$this->db->like('heading', $search);
}
$this->db->where('featured', '1');
$this->db->where('status', '1');
$this->db->where('cat_id', (int)$category);
$this->db->or_where('subcat_id', (int)$category);
$result_category_newss = $this->db->get('classifieds');
return $result_category_newss->result();
}
this is the model function i used to do search.
without $this->db->or_where('subcat_id', (int)$category);
it is working well
when i use the condition
$this->db->or_where('subcat_id', (int)$category);
it shows every fields in the table
can anyone help me???/
is there any syntax problem....
please reply
thanks in advance..
[eluser]Sudz[/eluser]
Now Try this one
Code: function get_ordinary_search($search, $category)
{
if($search!=‘all’){
$this->db->like(‘heading’, $search);
}
$this->db->where(‘cat_id’, (int)$category);
$this->db->or_where(‘subcat_id’, (int)$category);
$this->db->where(‘featured’, ‘1’);
$this->db->where(‘status’, ‘1’);
$result_category_newss = $this->db->get(‘classifieds’);
return $result_category_newss->result();
}
[eluser]Bigil Michael[/eluser]
problem is not solved
when i use
Quote:$this->db->or_where('subcat_id', (int)$category);
like statement is not working
can anyone help me
urgent......
[eluser]danmontgomery[/eluser]
AR doesn't group where clauses at all. So, your query says:
Code: SELECT * FROM `classifieds` WHERE `featured` = 1 AND `status` = 1 AND `cat_id` = $category OR `subcat_id` = $category
which will give you any thing with subcat_id = $category. You need to manually write the where clause if you want it grouped.
Code: if($search!=‘all’){
$this->db->like('heading', $search);
}
$this->db->where('(cat_id = '.(int)$category.' OR subcat_id = '.(int)$category.')', NULL, FALSE);
$this->db->where('featured', 1);
$this->db->where('status', 1);
[eluser]Bigil Michael[/eluser]
but it shows no result
[eluser]danmontgomery[/eluser]
so use:
Code: $this->output->enable_profiler();
to see what queries are being run, find the query, run it in phpmyadmin and see what the problem is
[eluser]Sudz[/eluser]
Put you or_where condition first then try it.
like this
Code: function get_ordinary_search($search, $category)
{
$this->db->where(‘cat_id’, (int)$category);
$this->db->or_where(‘subcat_id’, (int)$category);
$this->db->where(‘featured’, ‘1’);
$this->db->where(‘status’, ‘1’);
if($search!=‘all’){
$this->db->like(‘heading’, $search);
}
$result_category_newss = $this->db->get(‘classifieds’);
return $result_category_newss->result();
}
[eluser]Bigil Michael[/eluser]
but it will not echo the query
i applied like this
Quote:function get_ordinary_search($search, $category)
{
if($search!='all'){
$this->db->like('heading', $search);
}
$this->db->where('(cat_id = '.(int)$category.' OR subcat_id = '.(int)$category.')', NULL, FALSE);
$this->db->where('featured', '1');
$this->db->where('status', '1');
$result_category_newss = $this->db->get('classifieds');
$this->output->enable_profiler();
echo $result_category_newss;
return $result_category_newss->result();
}
and it shows some error
[eluser]Bigil Michael[/eluser]
Quote:function get_ordinary_search($search, $category)
{
$this->db->where(‘cat_id’, (int)$category);
$this->db->or_where(‘subcat_id’, (int)$category);
$this->db->where(‘featured’, ‘1’);
$this->db->where(‘status’, ‘1’);
if($search!=‘all’){
$this->db->like(‘heading’, $search);
}
$result_category_newss = $this->db->get(‘classifieds’);
return $result_category_newss->result();
}
it also has same problem
[eluser]Bigil Michael[/eluser]
can anyone help me????
urgent.....
|