Welcome Guest, Not a member yet? Register   Sign In
getting count from mysql
#1

[eluser]malcomhfc[/eluser]
Hi, i need some help with getting the number of rows where a certain value is true.

I have managed to do it for one call. However i need the where value to have different params.

For example.

if username = bob then count number of rows and return.
if password = banana then count number of rows and return.

This is what i have in the model so far

Code:
public function count_by($params = array())
{
  if ($params['status'] == 'open')
  {
   $this->db->where('status', $params['status']);
  }
  return $this->db->count_all_results('dev');
}

The above i need to check for status = draft and status = closed also.

the controller:
Code:
$status = $this->dev_m->count_by(array('status' => 'open'));

The view i just echo status. But im looking for a way to something along the lines of
Code:
echo status->open; echo status->closed;

I'm learning PHP and i don't want to make a variable for every count in the controller.

Any suggestions would be greatly appreciated.


Messages In This Thread
getting count from mysql - by El Forum - 07-13-2012, 01:12 PM
getting count from mysql - by El Forum - 07-14-2012, 06:18 AM
getting count from mysql - by El Forum - 07-14-2012, 11:48 AM
getting count from mysql - by El Forum - 07-14-2012, 12:32 PM
getting count from mysql - by El Forum - 07-14-2012, 12:56 PM
getting count from mysql - by El Forum - 07-14-2012, 01:03 PM



Theme © iAndrew 2016 - Forum software by © MyBB