We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

resultset count question

$result->count() is count users all rows.... how to know $result count?

docment is here

public int count ()

Counts how many rows are in the resultset

code is here

        $phql="SELECT * FROM Users WHERE UserName = :username: AND Password=:password:";
        $result =$this->modelsManager->executeQuery($phql,array('username' => $username,'password'=>$password));
        //var_dump($result->toarray());die();
        foreach ($result as $result)
        {
            echo $result->NickName, "\n";
            echo $result->count(), "\n";
        }

log is here

[Mon, 10 Feb 14 04:02:58 +0100][INFO] SELECT IF(COUNT(*)>0, 1 , 0) FROM `INFORMATION_SCHEMA`.`TABLES` WHERE `TABLE_NAME`='Users'
[Mon, 10 Feb 14 04:02:58 +0100][INFO] DESCRIBE `Users`
[Mon, 10 Feb 14 04:02:58 +0100][INFO] SELECT `Users`.`ID`, `Users`.`UserName`, `Users`.`Password`, `Users`.`NickName`, `Users`.`Email`, `Users`.`UserGroup`, `Users`.`UserACL` FROM `Users` WHERE `Users`.`UserName` = :username AND `Users`.`Password` = :password
[Mon, 10 Feb 14 04:02:58 +0100][INFO] SELECT COUNT(*) AS `rowcount` FROM `Users`


98.9k
Accepted
answer
edited Mar '14
foreach ($result as $result)

You're using the same variable to obtain every value in the resultset, so the resultset is being overridden. That's why $result->count() does not return the right number of results.