I have this example in the view where it works correctly:
$db = \Config\Database::connect();
$builder = $db->table('users');
$usuarios = $builder->countAll();
It counts all the users that I have in my users table. Now I want to do the following -> count all the results of the user_accept column of the users table (users table named above) and filter only by the result 1, that is, all the rows that have the value 1 that are counted.
I have tried the following:
$db = \Config\Database::connect();
$builder = $db->table('users');
$activos = $builder->select('user_accept')->where('user_accept'== 1);
$cont_activos = $builder->countAll('$activos');
But it doesn't work for me and it gives an error, does anyone know how to make the query builder work? Thank you.
The problem is that you are misusing the
where
.Try doing it like this:
More Info Query Builder Class > Looking for Specific Data