Yii Framework Forum: count number of records - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

count number of records Rate Topic: -----

#1 User is offline   nemo 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 142
  • Joined: 24-February 10

Posted 12 March 2010 - 08:18 AM

I can not display total number of data. I have one field, name "record", I want to display total records. Can any one help me?

This is my view file
<?php $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'columns'=>array(
'id',
'name',
'records_id',
'note',

),
)); ?>

Controller

public function actionView()
{
$dataProvider=new CActiveDataProvider('info', array(
'criteria'=>array(
'condition'=>'User_id =' .Yii::app()->user->id,
),

'pagination'=>array(
'pageSize'=>self::PAGE_SIZE,
),
));

$this->render('view',array(
'dataProvider'=>$dataProvider,
));
}

This is my sql command

SELECT count( records_id ) FROM `info` WHERE records_id IS NOT NULL AND User_id = 12 GROUP BY records_id
0

#2 User is offline   jsoo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 65
  • Joined: 01-March 10
  • Location:Durham, NC, USA

Posted 12 March 2010 - 08:55 AM

echo $dataProvider->getTotalItemCount();

0

#3 User is offline   nemo 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 142
  • Joined: 24-February 10

Posted 12 March 2010 - 09:27 AM

View Postjsoo, on 12 March 2010 - 08:55 AM, said:

echo $dataProvider->getTotalItemCount();



I don't want total records. I need SUM(records_id) field with group by . THis is my SQL command

SELECT count(records_id ) FROM `info` WHERE records_id IS NOT NULL AND User_id = 12 GROUP BY records_id


<?php $this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'columns'=>array(
'id',
'name',
'records_id',
'note',

),
)); ?>
0

#4 User is offline   jsoo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 65
  • Joined: 01-March 10
  • Location:Durham, NC, USA

Posted 12 March 2010 - 10:02 AM

Sorry. I just can't understand what you're asking. :(
0

#5 User is offline   nemo 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 142
  • Joined: 24-February 10

Posted 12 March 2010 - 11:21 AM

View Postjsoo, on 12 March 2010 - 10:02 AM, said:

Sorry. I just can't understand what you're asking. :(


Sorry about my english. Actually I want to count record_id field if record_id IS NOT NULL
0

#6 User is offline   jsoo 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 65
  • Joined: 01-March 10
  • Location:Durham, NC, USA

Posted 12 March 2010 - 12:10 PM

I think you can do this with

Info::model()->count($condition);


putting your WHERE clause into $condition, either as a string or an array to initialize a CDbCriteria.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users