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

Model\Query

$query = new Phalcon\Mvc\Model\Query("select *,count(FamilyUsers.id) as count from Family,FamilyUsers where Family.id=FamilyUsers.family_id group by family_id order by count limit 15",$this -> getDI());
$power_family = $query -> execute();

Could you tell me how can I get a query out value?



5.7k
Accepted
answer
edited Dec '14
$q = new \Phalcon\Mvc\Model\Query("SELECT * FROM Users", $this->getDI()); // Users model class
$result = $q->execute();
foreach ($result as $row) {
    echo "Name: ", $row->name, "<br>";
    echo "Email: ", $row->email, "<br>";
}
exit;

(Edit: Please ignore this part if it doesn't apply) Since you are using the limit, group by clauses, you could also use the find() method in Phalcon\Mvc\Model (https://docs.phalcon.io/en/latest/api/Phalcon_Mvc_Model.html). There is a separate static count() method in there too.