Pagination Problem

I have a strange pagination problem. I declare pagesize=20, but first page i got 10 data, second page blank, third page 3 and so on. I have no idea where is my problem. Here is my controller

public function actionAdmin()

{


	$this->processAdminCommand();





	$criteria=new CDbCriteria;





	$pages=new CPagination(Book::model()->count($criteria));


	$pages->pageSize=self::PAGE_SIZE;


	$pages->applyLimit($criteria);





	$sort=new CSort('Book');


	$sort->applyOrder($criteria);





	$models=Book::model()->findAll($criteria);


    	//$model->lab_id = Yii::app()->user->id;


	Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/js/jquery.tools.js');


	Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/js/jquery-impromptu.js');


	Yii::app()->clientScript->registerScript('tabs',$this->_tabScript, 4);


	


	


		$this->render('admin',array(


		'models'=>$models,


		'pages'=>$pages,


		'sort'=>$sort,


		));


	//}





		


}

view file

<table class="dataGrid">

<thead>

<tr>

&lt;th&gt;Actions&lt;/th&gt;


&lt;th&gt;&lt;?php echo &#036;sort-&gt;link('User_id'); ?&gt;&lt;/th&gt;	


&lt;th&gt;&lt;?php echo &#036;sort-&gt;link('name'); ?&gt;&lt;/th&gt;


&lt;th&gt;&lt;?php echo &#036;sort-&gt;link('phone'); ?&gt;&lt;/th&gt;	


&lt;th&gt;&lt;?php echo &#036;sort-&gt;link('book'); ?&gt;&lt;/th&gt;

</tr>

</thead>

<tbody>

<?php foreach($models as $n=>$model): ?>

&lt;?php if (&#036;model-&gt;User_id &gt;= '1'){ ?&gt;


&lt;tr class=&quot;&lt;?php echo &#036;n%2?'even':'odd';?&gt;&quot;&gt;


&lt;td&gt; &lt;?php echo CHtml::ajaxLink('test',array('update','id'=&gt;&#036;model-&gt;id),array('success'=&gt;&quot;function(data) {


				  		      	&#036;.prompt(data, {


				  		      		buttons: {Cancel: true } }) }&quot;)); ?&gt;


     


&lt;?php echo CHtml::linkButton('Delete',array(


  	  'submit'=&gt;'',


  	  'params'=&gt;array('command'=&gt;'delete','id'=&gt;&#036;model-&gt;id),


  	  'confirm'=&gt;&quot;Are you sure to delete #{&#036;model-&gt;id} - {&#036;model-&gt;book}?&quot;)); ?&gt;      					  		      		


&lt;/td&gt;				  		      		


&lt;td&gt;&lt;?php echo CHtml::activeDropDownList(&#036;model, 'User_id',CHtml::listData(CActiveRecord::model('User')-&gt;findAll(),'id','loginName'),array('disabled'=&gt;true)); ?&gt;&lt;/td&gt;


&lt;td&gt;&lt;?php echo CHtml::encode(&#036;model-&gt;name); ?&gt;&lt;/td&gt;


&lt;td&gt;&lt;?php echo CHtml::encode(&#036;model-&gt;phone); ?&gt;&lt;/td&gt;


&lt;td&gt;&lt;?php echo CHtml::encode(&#036;model-&gt;book); ?&gt;&lt;/td&gt;


 &lt;/tr&gt;  

<?php } ?>

<?php endforeach; ?>

</tbody>

</table>

I guess your dataset contains records with User_id != ‘1’. You need to limit the query criteria to one user and/or remove the if statement from the view.

/Tommy

would you please elaborate more or do you have example? That will really help me lot.

Thanks

Did you try to comment out these two lines of PHP code?




...

<?php // if ($model->User_id >= '1'){ ?>

...

<?php // } ?>

...



I misread the if statemement comparison operator for == ‘1’ (or perhaps you changed it recently). The pagination problem you described would still appear if $model->User_id evaluates to less than 1 (e.g if it’s a non-numerical string). If not, you don’t need the if statement so I conclude you don’t want to have the if statement there.

/Tommy

Actually I need this condition

<?php // if ($model->User_id >= ‘1’){ ?>

<?php // } ?>

is there any way or can I change the controller?

I guess your question relates to this question you asked recently:

count number of records

Seems to me like you want to create a report-style view presenting books grouped by user and perhaps with the user name and book count in the group header.

I can’t help you further until I’m going to do something similar myself. Too many loose ends.

/Tommy

You are right. I want to create a report-style view presenting books grouped by user and perhaps with the user name and book count in the group header. That’s why I need that condition. Can any one help me how to use that condition?

Never mind, I find the solution, in controller I add this line and working fine

$criteria->addCondition(“book_id = ‘1’ AND User_id >= ‘1’”);

is there is the same?

http://www.yiiframework.com/forum/index.php?/topic/6933-cpagination-models-count-limit-bug/page__hl__CPagination__fromsearch__1