Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7623935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:49:54+00:00 2026-05-31T04:49:54+00:00

I have a grid view with a condition upload_date = today, but when I

  • 0

I have a grid view with a condition “upload_date = today”, but when I search for other dates it is not filtering the grid. Here is my model:

public function search()
{
    // Warning: Please modify the following code to remove attributes that
    // should not be searched.
    $date=date('Y-m-d');
    $criteria=new CDbCriteria(array('order'=>'upload_date ASC'));
    $criteria->condition = "upload_date='$date' ";
     if(isset($_GET['upload_date']))
           {
           $criteria->addCondition('upload_date = :upload_date','AND'); 
          $criteria->params[':upload_date'] = $this->upload_date;
             }

    $criteria->compare('book_id',$this->book_id);
    $criteria->compare('date_received',$this->date_received,true);
    $criteria->compare('batch',$this->batch,true);
    $criteria->compare('isbn_no',$this->isbn_no,true);
    $criteria->compare('book_title',$this->book_title,true);
    $criteria->compare('auther_name',$this->auther_name,true);
    $criteria->compare('upload_date',$this->upload_date,true);

    return new CActiveDataProvider($this, array(
        'criteria'=>$criteria,
        'pagination'=>array(
        'pageSize'=>50
        ),

    ));
}

I am trying to use both condition and addcondition in same search. What did I do wrong in the model above?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T04:49:55+00:00Added an answer on May 31, 2026 at 4:49 am

    Try this:

    public function search()
    {
     $criteria=new CDbCriteria(array('order'=>'upload_date ASC'));
    
     if(isset($_GET['ModelName']['upload_date']))
     {
      $criteria->compare('upload_date',$this->upload_date,true);
      // $criteria->addCondition('upload_date = :upload_date');
      // $criteria->params[':upload_date'] = $this->upload_date;
     }
     else 
     {
      $date=date('Y-m-d');
      $criteria->condition = "upload_date='$date' "; 
     }
      $criteria->compare('book_id',$this->book_id);
      $criteria->compare('date_received',$this->date_received,true);
      $criteria->compare('batch',$this->batch,true);
      $criteria->compare('isbn_no',$this->isbn_no,true);
      $criteria->compare('book_title',$this->book_title,true);
      $criteria->compare('auther_name',$this->auther_name,true);
      $criteria->compare('upload_date',$this->upload_date,true);
    
      return new CActiveDataProvider($this, array(
         'criteria'=>$criteria,
         'pagination'=>array(
         'pageSize'=>50
         ), 
    
     ));
    }
    

    You don’t need addCondition, specially because you are adding a condition to the same column.

    Edit:
    In your main initial condition you have already set upload_date = $date, now if you add condition to it, say $_GET['ModelName']['upload_date'] provided by the user in the filter, your actual db query will become something like select * from tbl_name where upload_date = 'xxx' and upload_date = 'yyy' , here xxx=$date you gave, and yyy=date provided by user. Now if xxx != yyy, how will the query return any value? It is not possible.

    Hope you got this explanation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using vb.net code. I have grid view, please see the code below:
I have a grid view control in my application. Please see the below code.
I have a Data Grid View inside a control that is displayed in a
i have a doubt in grid view. In Data list we have a property
I have a page with .Net grid view with about 12 text fields per
I have used a list view that uses a grid view in WPF. I
Is it possible to have something like Data Grid or Grid View control in
How to implement CEditListCtrl?. List control with edit capabality (Report/Grid view). I have a
I have a databound grid at my view (XAML) and the Itemsource points to
i have a gridview with search option by a database table.All working fine but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.