[eluser]Bigil Michael[/eluser]
my code
Code:
function lekhanam($lekhanam) {
$lek = explode(',', $lekhanam);
if (!empty($lek))
{
foreach ($lek as $a1)
{
$this->db->or_where('a.id',$a1);
}
}
$this->db->limit(5);
$this->db->where('a.status',1);
$this->db->where('at.status',1);
$this->db->select('a.*, ac.category_name, at.id as author_id, at.name, at.photo as authorimage');
$this->db->from('articles AS a');
$this->db->join('article_categories AS ac', 'ac.category_id = a.category_id');
$this->db->join('authors AS at', 'at.id = a.author_id');
$result= $this->db->get();
return $result->result();
}
here problem is status not working.
so i print the query
Code:
SELECT `a`.*, `ac`.`category_name`, `at`.`id` as author_id, `at`.`name`, `at`.`photo` as authorimage FROM (`articles` AS a) JOIN `article_categories` AS ac ON `ac`.`category_id` = `a`.`category_id` JOIN `authors` AS at ON `at`.`id` = `a`.`author_id` WHERE `a`.`id` = '7' OR `a`.`id` = '8' OR `a`.`id` = '9' OR `a`.`id` = '10' OR `a`.`id` = '11' AND `a`.`status` = 1 AND `at`.`status` = 1 LIMIT 5
when i put a bracket between where and AND like this
Code:
SELECT `a`.*, `ac`.`category_name`, `at`.`id` as author_id, `at`.`name`, `at`.`photo` as authorimage FROM (`articles` AS a) JOIN `article_categories` AS ac ON `ac`.`category_id` = `a`.`category_id` JOIN `authors` AS at ON `at`.`id` = `a`.`author_id` WHERE (`a`.`id` = '7' OR `a`.`id` = '8' OR `a`.`id` = '9' OR `a`.`id` = '10' OR `a`.`id` = '11') AND `a`.`status` = 1 AND `at`.`status` = 1 LIMIT 5
It runs fine .
I dont know how to put a bracket in codeigniter query.
can any one modify this query..
thanks ...