Buddha Andrade
Buddha Andrade

Reputation: 49

How count the number of records in a table and print the result using Querybuilder in Yii

I'm new to the Yii Framework, and I'm trying to run a query so I can count the number of records in a table and print it in my index.php (under view/site/index.php)

Here my sql code

SELECT COUNT(id) AS id FROM entidades WHERE sectores_id=2

I've searched and found about Querybuilder in Yii but I can't make it work.

Any help??

Upvotes: 0

Views: 107

Answers (1)

Buddha Andrade
Buddha Andrade

Reputation: 49

I've solved the problem with the folowing code. In my view/site/index.php i've added.

<?php $count2 = Entidades::model()->countByAttributes(array('sectores_id' => '2'));
                echo $count2;
            ?>

Upvotes: 1

Related Questions