Yii Framework Forum: How To Find Exact Values Using Cgridview Filter - Yii Framework Forum

Jump to content

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

How To Find Exact Values Using Cgridview Filter When Get Values from Different Models. Rate Topic: ****- 1 Votes

#1 User is offline   sprymanish 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 07-June 12

Posted 08 February 2013 - 12:20 AM

Hii In yii framework Cgirdview, I Want to find exact values in cgridview which I given in the cgridview filters.
It means if the filtered results show only 1 result but it is same as exacted which I given in filter.
:rolleyes:

Thanks in advance:

Here is my code:

Model:


public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.

$criteria=new CDbCriteria;
if(!empty($this->met_not_less)){
$criteria->condition="totmetalwei > :met_not_less";
$criteria->params[':met_not_less']=$this->met_not_less;
}
if(!empty($this->met_not_more)){
$criteria->condition="totmetalwei < :met_not_more ";
$criteria->params[':met_not_more']=$this->met_not_more;
}
$criteria->compare('idsku',$this->idsku);
$criteria->compare('skucode',$this->skucode,true);
$criteria->compare('tdnum',$this->tdnum,true);
$criteria->compare('cdate',$this->cdate,true);
$criteria->compare('mdate',$this->mdate,true);
$criteria->compare('updby',$this->updby);
$criteria->compare('leadtime',$this->leadtime);
$criteria->compare('refpo',$this->refpo);
$criteria->compare('parentsku',$this->parentsku);
$criteria->compare('parentrel',$this->parentrel,true);
$criteria->compare('taxcode',$this->taxcode,true);
$criteria->compare('dimunit',$this->dimunit,true);
$criteria->compare('dimdia',$this->dimdia,true);
$criteria->compare('dimhei',$this->dimhei,true);
$criteria->compare('dimwid',$this->dimwid,true);
$criteria->compare('dimlen',$this->dimlen,true);
$criteria->compare('totmetalwei',$this->totmetalwei,true);
$criteria->compare('metweiunit',$this->metweiunit,true);
$criteria->compare('totstowei',$this->totstowei,true);
$criteria->compare('stoweiunit',$this->stoweiunit,true);
$criteria->compare('numstones',$this->numstones);
$criteria->compare('grosswt',$this->grosswt);

if(!empty($this->type)) $criteria->with[] = 'skucontent';
if(!empty($this->gemstone)) $criteria->with[] = 'stones';
if(!empty($this->gem_shape)) $criteria->with[] = 'shapes';
if(!empty($this->gem_size)) $criteria->with[] = 'sizes';
if(!empty($this->type) || !empty($this->gemstone) || !empty($this->gem_shape) || !empty($this->gem_size)) $criteria->together = true;
if(!empty($this->type)) $criteria->compare( 'skucontent.type', $this->type, true );

if(!empty($this->gemstone)) $criteria->compare('stones.namevar',$this->gemstone, true);
if(!empty($this->gem_shape)) $criteria->compare('shapes.name',$this->gem_shape, true);
if(!empty($this->gem_size)) $criteria->compare('sizes.size',$this->gem_size, true);
if(!empty($this->sku_size)) $criteria->compare( 'skucontent.size', $this->sku_size, true );
return new CActiveDataProvider(get_class($this), array(
'criteria'=>$criteria,
));
}

Attached File  results.JPG (50.53K)
Number of downloads: 14
0

#2 User is offline   Sukhwinder 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 51
  • Joined: 27-October 09

Posted 08 February 2013 - 12:46 AM

View Postsprymanish, on 08 February 2013 - 12:20 AM, said:

Hii In yii framework Cgirdview, I Want to find exact values in cgridview which I given in the cgridview filters.
It means if the filtered results show only 1 result but it is same as exacted which I given in filter.
:rolleyes:

Thanks in advance:

Here is my code:

Model:


public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.

$criteria=new CDbCriteria;
if(!empty($this->met_not_less)){
$criteria->condition="totmetalwei > :met_not_less";
$criteria->params[':met_not_less']=$this->met_not_less;
}
if(!empty($this->met_not_more)){
$criteria->condition="totmetalwei < :met_not_more ";
$criteria->params[':met_not_more']=$this->met_not_more;
}
$criteria->compare('idsku',$this->idsku);
$criteria->compare('skucode',$this->skucode,true);
$criteria->compare('tdnum',$this->tdnum,true);
$criteria->compare('cdate',$this->cdate,true);
$criteria->compare('mdate',$this->mdate,true);
$criteria->compare('updby',$this->updby);
$criteria->compare('leadtime',$this->leadtime);
$criteria->compare('refpo',$this->refpo);
$criteria->compare('parentsku',$this->parentsku);
$criteria->compare('parentrel',$this->parentrel,true);
$criteria->compare('taxcode',$this->taxcode,true);
$criteria->compare('dimunit',$this->dimunit,true);
$criteria->compare('dimdia',$this->dimdia,true);
$criteria->compare('dimhei',$this->dimhei,true);
$criteria->compare('dimwid',$this->dimwid,true);
$criteria->compare('dimlen',$this->dimlen,true);
$criteria->compare('totmetalwei',$this->totmetalwei,true);
$criteria->compare('metweiunit',$this->metweiunit,true);
$criteria->compare('totstowei',$this->totstowei,true);
$criteria->compare('stoweiunit',$this->stoweiunit,true);
$criteria->compare('numstones',$this->numstones);
$criteria->compare('grosswt',$this->grosswt);

if(!empty($this->type)) $criteria->with[] = 'skucontent';
if(!empty($this->gemstone)) $criteria->with[] = 'stones';
if(!empty($this->gem_shape)) $criteria->with[] = 'shapes';
if(!empty($this->gem_size)) $criteria->with[] = 'sizes';
if(!empty($this->type) || !empty($this->gemstone) || !empty($this->gem_shape) || !empty($this->gem_size)) $criteria->together = true;
if(!empty($this->type)) $criteria->compare( 'skucontent.type', $this->type, true );

if(!empty($this->gemstone)) $criteria->compare('stones.namevar',$this->gemstone, true);
if(!empty($this->gem_shape)) $criteria->compare('shapes.name',$this->gem_shape, true);
if(!empty($this->gem_size)) $criteria->compare('sizes.size',$this->gem_size, true);
if(!empty($this->sku_size)) $criteria->compare( 'skucontent.size', $this->sku_size, true );
return new CActiveDataProvider(get_class($this), array(
'criteria'=>$criteria,
));
}

Attachment results.JPG


Try the third parameter of CDbcriteria->compare() as false, which will do the exact match in stead of like condition. You can also check the exact query being fired by Yii in Log and see the reason for duplicate result.
0

#3 User is offline   sprymanish 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 07-June 12

Posted 08 February 2013 - 01:02 AM

View PostSukhwinder, on 08 February 2013 - 12:46 AM, said:

Try the third parameter of CDbcriteria->compare() as false, which will do the exact match in stead of like condition. You can also check the exact query being fired by Yii in Log and see the reason for duplicate result.


Hi thanks in advance, thaks for your helpfull reply but now I am not able to find, Can you please send me the code which you have done it same which I want.

Many Thanks
0

#4 User is offline   Sukhwinder 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 51
  • Joined: 27-October 09

Posted 08 February 2013 - 01:43 AM

View Postsprymanish, on 08 February 2013 - 01:02 AM, said:

Hi thanks in advance, thaks for your helpfull reply but now I am not able to find, Can you please send me the code which you have done it same which I want.

Many Thanks

See the API of Cdbcriteria()::compare() at
CDbcriteria::compare()
0

#5 User is offline   sprymanish 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 10
  • Joined: 07-June 12

Posted 08 February 2013 - 03:02 AM

View PostSukhwinder, on 08 February 2013 - 01:43 AM, said:

See the API of Cdbcriteria()::compare() at
CDbcriteria::compare()


Thanks for your reply
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