Yii Framework Forum: How To Return Results From Database Where A Column Matches A Value? - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

How To Return Results From Database Where A Column Matches A Value? Rate Topic: ***** 1 Votes

#1 User is offline   mayonaise 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 28-January 13

Posted 29 January 2013 - 02:12 PM

The code below returns all records from a database table.

    $criteria = array(
      'pagination' => array('pageSize' => 20),
      'sort' => array(
        'defaultOrder' => 'id DESC',
      ),
    );

    $dataProvider = new CActiveDataProvider('Step1', $criteria);


I need to modify it so it will only return records where a column matches a specific value. For example, only show records where "microsoft.com" is in the "site" column of the database.

    $criteria = array(
      ':site' => Yii::app()->params['src'],
      'pagination' => array('pageSize' => 20),
      'sort' => array(
        'defaultOrder' => 'id DESC',
      ),
    );

    $dataProvider = new CActiveDataProvider('Step1', $criteria);


Can someone tell me what I'm doing wrong?
0

#2 User is offline   seenivasan 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 620
  • Joined: 17-June 12
  • Location:Chennai,TamilNadu,India.

Posted 29 January 2013 - 02:37 PM

Dear Friend

Kindly check this.
$criteria=new CDbCriteria;
$criteria->addSearchCondition("site",Yii::app()->params['src']);//assumed that column name is site.

$dataProvider = new CActiveDataProvider('Step1', array(
    "criteria"=>$criteria,
    "pagination" => array('pageSize' => 20),
    "sort" => array(
        'defaultOrder' => 'id DESC',)

));


Regards.
1

#3 User is offline   mayonaise 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 7
  • Joined: 28-January 13

Posted 29 January 2013 - 02:40 PM

Thanks so much. That worked perfect!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users