I am using Yii framework, I want to do some search filtering, but I am getting wrong results in some cases as follow:
I have 2 check-boxes: Canada and united states, if I check Canada I will get all the results related to Canada only, while if I check united states I will get all the results in the db regardless its related to united states or not, and this bug is absolutely happen because united states string is of 2 parts so it need to be in quotations. here is my code:
the view page:
echo '<div class="checkbox"><label>'.
CHtml::checkBox($m2->tag, false, array('value'=>"$m2->tag")).$m2->tag
.'</label></div>';
the controller:
$c = new CDbCriteria();
$c->order = "idJob DESC";
$model = Jobs::model()->findAll($c);
$model2 = Tags::model()->findAll();
$lcr = "";
$tag="";
foreach($model2 as $m2){
if(isset($_POST[$m2->tag])){
$tag = $_POST[$m2->tag];
if($m2->category=='Location')
$lcr[]= $tag;
}
}
if($lcr!="")
$c->addInCondition('location', $lcr, 'AND');
$model = Jobs::model()->findAll($c);