Counting The Total No Of Records In A Table

Hi all,

i made web service using this extention

http://www.yiiframework.com/extension/restfullyii/

anyone plz help me to get the count of total no of records in a table

this is may data table

CREATE TABLE IF NOT EXISTS places (

id int(60) NOT NULL AUTO_INCREMENT,

name varchar(255) NOT NULL,

discription text NOT NULL,

image varchar(255) NOT NULL,

city_id int(60) NOT NULL,

hotel_id int(60) NOT NULL,

catagory_id int(60) NOT NULL,

type_id int(60) NOT NULL,

latitute float NOT NULL,

longtute float NOT NULL,

metadata text NOT NULL,

PRIMARY KEY (id),

UNIQUE KEY id (id),

KEY city_id (city_id),

KEY hotel_id (hotel_id),

KEY catagory_id (catagory_id),

KEY type_id (type_id)

) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=16 ;

i use this paser for get list of places related with id in TypePlaces table(API controller)

switch($_GET[‘model’])

    {


        case 'places': // {{{


            //get list of places related with id in TypePlaces table 


			//http://localhost/TheGuidersite_service/index.php/api/Places?typeplacesid=1			 


			if (isset($_GET['typeplacesid']))


			{


				$Criteria = new CDbCriteria();


				$Criteria->condition = sprintf("type_id = %s", $_GET['typeplacesid']);


				$models = Places::model()->findAll($Criteria);


			 


			}

but now i ned get number of places related with type_id how count this :-[


print_r(array_count_values($models));

is this correct

i need get total num of record

$Criteria = new CDbCriteria();

$Criteria->condition = sprintf(“type_id = %s”, $_GET[‘Typeplaceid’]);

$models = Places::model()->count($Criteria);

Do this after your last line of code in your example:


$models = Places::model()->findAll($Criteria);


$totalRecords = count($models);

Or you could do something like this:


$q = 'SELECT COUNT(id) FROM places';

$totalRecords  = Yii::app()->db->createCommand($q)->queryScalar();

i use RESTFUL api controller to preview data i need add this in to my places model and preview it from browser

how do this this is my API controller