【发布时间】:2016-05-12 21:25:35
【问题描述】:
我在我的列表页面中使用搜索项实现分页 (yii1):当我搜索某些内容时,分页总项 5(我的意思是像 1 2 3 4 5 这样的链接)并且搜索很好。
当我点击分页链接中的第二页时,项目总数增加到 12(我的意思是像 1 2 3 4 5 ...10 11 12 这样的链接)。
我的查询与 like 运算符一起工作正常。我不知道它在哪里 变了..
这是在我的控制器中
if((isset($_POST['searchtext'])) && (!empty($_POST['searchtext']))){
$sql ="select * from table1 where name LIKE '\'%'.$_POST['searchtext'].'%\'" ;
$sql_count = "select count(*) from table1 LIKE '\'%'.$_POST['searchtext'].'%\'" ;
$count=Yii::app()->db->createCommand($sql_count)->queryScalar();
}else{
$sql = "select * from table1";
$sql_count = "select * from table1";
$count=Yii::app()->db->createCommand($sql_count)->queryScalar();
}
$dataProvider=new CSqlDataProvider($sql, array(
'totalItemCount'=>$count,
'sort'=>array(
'attributes'=>array(
'id','userid','user_email',
),
),
'pagination'=>array(
'pageSize'=>9,
),
));
$this->render('listallview',array(
'dataProvider'=>$dataProvider,
));
我的看法
<ul class="list ">
<?php
$this->widget('bootstrap.widgets.TbListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
));
?>
</ul>
可能是什么问题?
【问题讨论】: