baby machinery baby machinery - 2 months ago 28x
PHP Question

Get all post and count from db phalcon

i have 2 user in my blog. there user-1 have 3 post. in this case visitors visit post-1' 20 time, post-2 40 time and post-3 100 time. and user-2 have 2 post which visitors visits 15 and 40 times. i want to count all the post for each user in phalcon. i cant figure it out. im am unable to bind or make this query.


public function index()
$pcount = Blogs::findBybauthor($this->session->get('uname'));
$posted = count($pcount);
$x = [];
$v = Blogs::findBybauthor($this->session->get('uname'));
foreach($v as $a)


I am currently not able to verify this example. But from looking at the docs, this should point you in the right direction.

Instead of using find we are using sum.

This will return an array with the total amount of views, grouped by author.

$viewsPerAuthor = Blogs::sum(
        "column" => "views",
        "group"  => "bauthor"

This will return the total amount of views for a specific author

$total = Blogs::sum(
        "column"     => "views",
        "conditions" => "bauthor = '" . $this->session->get('uname') . "'"

*note that using bind parameters in the last example should be a better practice