Welcome Guest, Not a member yet? Register   Sign In
Compare data from two different tables using codeigniter
#1

[eluser]Unknown[/eluser]
I am new to codeigniter and I want to write this mySql query
Code:
SELECT COUNT(DISTINCT source) AS NumberOfEvaluations
FROM COMMENT , EVALUATION
WHERE evaluation_id = EVALUATION.id AND EVALUATION.department_id = '$department_id' ;

into codeigniter.
This is my try

Code:
$this->db->select('t1.count(DISTINCT(source))');  
   $this->db->from('comment t1');
   $this->db->join('evaluation t2', 't2.id = t1.evaluation_id', 'left');    

   $this->db->where();
  
$query=$this->db->get();  
   return $query->num_rows();
#2

[eluser]Unknown[/eluser]
Maybe this one ?
Code:
$this->db->select('count(DISTINCT(source))');  
$this->db->from('comment c','evaluation e');  

$this->db->where('c.evaluation_id','e.id');
$this->db->where('e.department_id', $department_id);
#3

[eluser]TheFuzzy0ne[/eluser]
Welcome to the CodeIgniter forums!

You didn't mention what the problem was.

I assume you're having trouble with CodeIgniter escaping your SELECT clause? You can pass FALSE into $this->db->select() as the second parameter to prevent that.
Code:
$this->db->select('count(DISTINCT source)', FALSE);  
$this->db->from('comment c','evaluation e');  

$this->db->where('c.evaluation_id','e.id');
$this->db->where('e.department_id', $department_id);




Theme © iAndrew 2016 - Forum software by © MyBB