-1

I've got a problem that needs fixing and I can't seem to figure it out.

So, I use this method (part of method that's troublesome) to get total users when listed for pagination:

$up = Users::totalUsers($condition);
        $totalPages= ceil($up / App::config('rps'));
`

Then I go to model and count everyone:

    public static function totalUsers($condition)
    {
        $conn= DB::getInstance();
        $exp= $conn->prepare('
        
        select count(id) from users where concat(name,\'\',
        surname,\'\',email,\'\',username)
        like :condition
        
        ');
        $condition= '%' . $condition. '%';
        $exp->bindParam('condition',$condition);
        $exp->execute();
        return $exp->fetchAll();
    }

Tried adding PDO::PARAM_INT like

('condition',$condition,PDO::PARAM_INT)

but it also doesn't work.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345

1 Answers1

-1

fetchAll() returns an array, which you then try to divide by an integer. Try adding a [0] subscript or two to the last line of totalUsers() between the parentheses and the semicolon so it's like

return $exp->fetchAll()[0][0];

This way totalUsers() will return an integer (well, actually a string which can be converted to integer) and you will be able to divide it by the other integer.

Nathan Mills
  • 2,243
  • 2
  • 9
  • 15