Yii Framework Forum: Searching within two columns using the standard search model method - Yii Framework Forum

Jump to content

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

Searching within two columns using the standard search model method Rate Topic: -----

#1 User is offline   YIINewBy 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 41
  • Joined: 11-September 09
  • Location:Pretoria, South Africa

Posted 04 June 2010 - 05:34 PM

I have 2 columns namely name and surname that are concatenated in a column in the CGridView. Now Yii comes standard with an type on inline searching, at the top of each column. Now the name column which contains "concatenated name and surname and two seperate columns in database"

If user types in a word in the name column search i want it to search within the name and surname db column and tread these columns as one value.

Now in the search method I'm not sure how to accomplish this

Could

$criteria->compare('name',$this->name,true);
$criteria->compare('surname',$this->name,true);


be converted to something like

name LIKE '%".$this->name."%' OR surname LIKE '%".$this->name."%'
using $criteria->compare


Any help will be highly appreciated
0

#2 User is offline   zaccaria 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 2,232
  • Joined: 04-October 09
  • Location:Moscow

Posted 07 June 2010 - 07:46 AM

Simpy do

$criteria->addcondition("(name LIKE '%".$this->name."%' OR surname LIKE '%".$this->name."%')");


There is the possibility of do

$criteria->compare('name',$this->name,true);
$criteria->compare('surname',$this->name,true, 'OR');


But this solution will not add the brakets, and the surname will be in or with all other conditions.
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