具有精确值的 Yii 过滤器选项

发布于 2025-01-04 13:10:50 字数 845 浏览 2 评论 0原文

我有一个带有数据库表搜索选项的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爺獨霸怡葒院 2025-01-11 13:10:50

您可以设置任何类型的 mySql WHERE 条件 您想要的这个:

$criteria->addCondition('proc_id = :procid'); // add your sql WHERE condition
$criteria->params[':procid'] = $this->proc_id; // bind your parameter

应该能够使用compare() ,但您可能必须将 ID 转换为整数:

$criteria->compare('proc_id', (int) $this->proc_id);

You can set up any kind of mySql WHERE condition you want like this:

$criteria->addCondition('proc_id = :procid'); // add your sql WHERE condition
$criteria->params[':procid'] = $this->proc_id; // bind your parameter

You should be able to use compare() though, but you might have to cast the ID to an integer:

$criteria->compare('proc_id', (int) $this->proc_id);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文