• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trouble with DB query

#1
[eluser]Unknown[/eluser]
Hello,

I'm new to CI and I faced a problem at the moment. Any advice will be appreciated!

Code:
$faulty = $this->db->select('COUNT(*) as f_count')
                          ->from("TABLE")
                          ->where('ttime BETWEEN "'.$tstart.'" AND "'.$tend.'"')
                          ->where('rtime = 0')
                          ->where_in("mid", $mids)
                          ->group_by("mid")
                          ->get();

What I'm trying to do is that, from "TABLE" I want to count number of row respect to each mid that has the condition of rtime = 0. It does return some values but not fully. The problem is that when there are no row found, I want it to be return '0' for corresponding mid but it just skips.

For better understanding:
TABLE
mid | rtime
---------------
A |rtime = 3
A |rtime = 0
A |rtime = 1
B |rtime = 5
B |rtime = 0
B |rtime = 0
C |rtime = 3

And as a result:
A = 1
B = 2

Which I desire is:
A = 1
B = 2
C = 0

I did some research, and MYSQL has 'ISNULL()' or ' COALESCE()' which will do the job.
I couldn't find in Active Record (or just that it's there and I couldn't understand...) in CI.


Thank you for reading my post!
-Dan


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.