Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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?



3.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 (http://docs.phalconphp.com/en/latest/api/Phalcon%5Mvc%5Model.html). There is a separate static count() method in there too.