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

Count all rows in compound query

I have compound query

$query = $this->getDi()->get('modelsManager')->createBuilder()
->columns(...)
->from(...)
->join(...)
->join(...)
...
->where(...)
->orderBy(...)
->limit(12)
...

How count all rows without limit?

I think it should be works.

$query = $this->getDi()->get('modelsManager')->createBuilder()
->columns(...)
->from(...)
->join(...)
->join(...)
...
->where(...)
->orderBy(...)
//->limit(12) // remove
->count(); // add

Hi @stanleer you can get the count with this simple way


    $myCount = $this->getDi()->get('modelsManager')->createBuilder()
    ->columns(['myCount' => 'count(*)']) //myCount alias
    ->from(...)
    ->where(...)
    ->getQuery()
    ->setUniqueRow(true)
    ->execute()
    ->myCount; //myCount property

Good luck