Not sure if I’m doing this correct but could do with some assistance. This is what I have at the moment:
$criteria=new CDbCriteria;
if(Yii::app()->user->type == 2)
$criteria->addCondition("user_id=".Yii::app()->user->id);
$criteria->addCondition("enquiry_status=2");
if(Yii::app()->user->type == 2)
$criteria->addCondition("enquiry_status=1", "OR");
Hopefully from this you can establish what I’m trying to do. So when the user type is 2 I add in a condition to search the user_id. Also when the user type is 2 I add in a condition to search for enquiry_status 1.
The resultset that is bought back from this query is incorrect; essentially the query needs to be as follows:
SELECT * FROM enquiry e WHERE enquiry_status=2;
SELECT * FROM enquiry e WHERE user_id=2 AND (enquiry_status=2 OR enquiry_status=1);
How do I correct my conditions so that the queries are executed as above?