Yii Framework Forum: As If To Add Criteria? - Yii Framework Forum

Jump to content

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

As If To Add Criteria? Rate Topic: -----

#1 User is offline   alexd2 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 12-September 12

Posted 05 October 2012 - 09:09 AM

In a conditional use mysql to do so

SELECT IF (data> 2, data, 3) WHERE status = 1


As you can add if (data> 2, data, 3) criteria?
0

#2 User is online   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,511
  • Joined: 04-March 10
  • Location:UK

Posted 05 October 2012 - 09:30 AM

I don't understand the question, can you try to restate it?

As an aside, in MySQL, you can use GREATEST():
SELECT GREATEST(data, 3) WHERE status = 1

0

#3 User is offline   alex-w 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 223
  • Joined: 25-November 10

Posted 05 October 2012 - 09:41 AM

Think this will work.

MyModel::model()->find([
  'select' => ['IF(data>2, data, 3) AS data'],
  'condition' => 'status=1'
]);

0

#4 User is offline   alexd2 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 12-September 12

Posted 05 October 2012 - 10:13 AM

View Postalex-w, on 05 October 2012 - 09:41 AM, said:

Think this will work.

MyModel::model()->find([
  'select' => ['IF(data>2, data, 3) AS data'],
  'condition' => 'status=1'
]);




If that's the idea, I'll try it and see if it works.
0

#5 User is offline   alexd2 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 12-September 12

Posted 13 October 2012 - 05:59 PM

//Model
class Mytest extends CActiveRecord
{
public $newdata;
...
...

$criteria=new CDbCriteria;
$criteria->select = array("*"," if(data > 2, data, 3) AS newdata");
...
...
}


It's work...
1

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