Hello dears.
How can I set two conditions on CDBCriteria.
Actually I am saving the Ads record in which I have implement the counter, i.e. the "views" field value will be increased automatically when the index page (site index page) will be refreshed.
In the Ads form I also get the no_of_presentations, i.e. how many times the Ad should be displayed.
Now on the index page I have implement a criteria in which I want to set the condition that the Ad will be displayed if the "views <= no_of_presentations"(i.e. views are less than or equal to no_of_presentations) .
and also it has the ad_group field which points to the Ad group i.e. side ad or top ad.
the code for that which I have create is
<?php
$criteria = new CDbCriteria();
$criteria->addCondition('ad_group = 1', null, 'AND');
$criteria->addCondition('views < no_of_presentations');
$criteria->limit = 1;
$criteria->order = 'create_date DESC';
$topadvertisement = Ads::model()->findAll($criteria);
foreach ($topadvertisement as $data):
?>
<a href="<?php echo $data->ad_url; ?>" target="_blank"><?php echo CHtml::image(yii::app()->baseUrl . '/media/ads/original/' . $data->ad_image, $data->title, array('class' => 'img-responsive')); ?> </a>
<?php
$admodel = Ads::model()->findByPk($data->id);
$admodel->views += 1;
$admodel->save(false);
endforeach;
?>
but it is not displaying the ad as the "views <= no_of_presentations"(i.e. views are less than or equal to no_of_presentations) condition is satisfied.
Thanks in advance.