具有精确值的 Yii 过滤器选项
我有一个带有数据库表搜索选项的 gridview。一切正常,但问题是当我输入 id 值来搜索网格时,它会显示所有相关的值行。例如,如果我输入值“1”,它会过滤所有 1,例如 1,10,11,12,13,.... 但我需要只显示我输入的确切值它应该只显示相应的行我希望你理解我的问题...
我的模型如下所示
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria(array('order'=>'proc_id DESC'));
//$criteria->condition = " status = 'Active' ";
$criteria->compare('proc_id',$this->proc_id);
$criteria->compare('book_id',$this->book_id,true);return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'pagination'=>array(
'pageSize'=>50
),
));
}
嗨我找到了我的问题的答案我刚刚从我的代码中删除了 true 如下
$criteria->compare('book_id',$this->book_id);
i have a gridview with search option by a database table.All working fine but the problem is when i enter a id value to search my grid it shows all the related value rows. For example if i enter value "1" it filters all 1's like 1,10,11,12,13,....
But i need to show only exact value what i entered it should show only the corresponding row i hope u understand my prob...
my model is like below
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria(array('order'=>'proc_id DESC'));
//$criteria->condition = " status = 'Active' ";
$criteria->compare('proc_id',$this->proc_id);
$criteria->compare('book_id',$this->book_id,true);return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
'pagination'=>array(
'pageSize'=>50
),
));
}
hi i found the answer for my problem i just removed true from my code as below
$criteria->compare('book_id',$this->book_id);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以设置任何类型的 mySql WHERE 条件 您想要的这个:
您应该能够使用compare() ,但您可能必须将 ID 转换为整数:
You can set up any kind of mySql WHERE condition you want like this:
You should be able to use compare() though, but you might have to cast the ID to an integer: