CodeIgniter: How To Do A Select (Distinct Fieldname) MySQL Query


Answer :

$record = '123';  $this->db->distinct();  $this->db->select('accessid');  $this->db->where('record', $record);   $query = $this->db->get('accesslog'); 

then

$query->num_rows(); 

should go a long way towards it.


You can also run ->select('DISTINCT `field`', FALSE) and the second parameter tells CI not to escape the first argument.

With the second parameter as false, the output would be SELECT DISTINCT `field` instead of without the second parameter, SELECT `DISTINCT` `field`


try it out with the following code

function fun1()   {      $this->db->select('count(DISTINCT(accessid))');      $this->db->from('accesslog');      $this->db->where('record =','123');      $query=$this->db->get();      return $query->num_rows();   } 

Comments

Popular posts from this blog

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Can Feynman Diagrams Be Used To Represent Any Perturbation Theory?