-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.

0

1 Answer 1

-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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.