Yii Framework Forum: Search/filtering Two Concatenated Columns In Cgridview - Yii Framework Forum

Jump to content

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

Search/filtering Two Concatenated Columns In Cgridview Rate Topic: -----

#1 User is offline   hameedhamdani 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 82
  • Joined: 20-October 12
  • Location:Islambad,Pakistan

Posted 20 November 2012 - 01:48 AM

Hi,
i have concated two columns.but its filetering and searching is not working.
my code for controller

public $client_name;

$criteria->compare('CONCAT(first_name,last_name)',$this->client_name,true);

my code for view

array(
'header'=>'Client Name',
'name'=>'client_name',
'value'=>'$data->first_name." ".$data->last_name',
),

Concatenation and displaying is done but seraching the data show no results found?

plz help.thanks in advance.
0

#2 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,483
  • Joined: 04-March 10
  • Location:UK

Posted 20 November 2012 - 04:00 AM

Have you updated your model's search method?
0

#3 User is offline   hameedhamdani 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 82
  • Joined: 20-October 12
  • Location:Islambad,Pakistan

Posted 20 November 2012 - 04:26 AM

View PostKeith, on 20 November 2012 - 04:00 AM, said:

Have you updated your model's search method?


yes i updated the search method as

$criteria->compare('CONCAT(first_name,last_name)',$this->first_name,true);
0

#4 User is offline   Jimlam 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 195
  • Joined: 17-March 12

Posted 20 November 2012 - 05:26 AM

View Posthameed, on 20 November 2012 - 04:26 AM, said:

yes i updated the search method as

$criteria->compare('CONCAT(first_name,last_name)',$this->first_name,true);


Try

$criteria->compare('CONCAT_WS(' ',first_name,last_name)',$this->client_name,true);


If client_name is not an attribute in your db, declare it in your model as

public $client_name


Add it also as safe on search in your model
0

#5 User is offline   hameedhamdani 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 82
  • Joined: 20-October 12
  • Location:Islambad,Pakistan

Posted 20 November 2012 - 05:39 AM

View PostJimlam, on 20 November 2012 - 05:26 AM, said:

Try

$criteria->compare('CONCAT_WS(' ',first_name,last_name)',$this->client_name,true);


If client_name is not an attribute in your db, declare it in your model as

public $client_name


Add it also as safe on search in your model



yes i declare it as
public $client_name

and add it in safe search as
array('id, first_name, last_name, email_address,client_name', 'safe', 'on'=>'search'),

and in search() criteria as

$criteria->compare('CONCAT_WS(' ',first_name,last_name)',$this->client_name,true);

and in cgrigview as

array(
'header'=>'Client Name',
'name'=>'client_name',
'value'=>'$data->first_name." ".$data->last_name',
),

But the error Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING $criteria->compare('CONCAT_WS(' ',first_name,last_name)',$this->client_name,true);


plz reply thanks
0

#6 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,483
  • Joined: 04-March 10
  • Location:UK

Posted 20 November 2012 - 05:48 AM

Replace either the inner or outer single quotes with double quotes:

$criteria->compare('CONCAT_WS(" ",first_name,last_name)',$this->client_name,true);

0

#7 User is offline   hameedhamdani 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 82
  • Joined: 20-October 12
  • Location:Islambad,Pakistan

Posted 20 November 2012 - 05:51 AM

View Posthameed, on 20 November 2012 - 05:39 AM, said:

yes i declare it as
public $client_name

and add it in safe search as
array('id, first_name, last_name, email_address,client_name', 'safe', 'on'=>'search'),

and in search() criteria as

$criteria->compare('CONCAT_WS(' ',first_name,last_name)',$this->client_name,true);

and in cgrigview as

array(
'header'=>'Client Name',
'name'=>'client_name',
'value'=>'$data->first_name." ".$data->last_name',
),

But the error Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING $criteria->compare('CONCAT_WS(' ',first_name,last_name)',$this->client_name,true);


plz reply thanks



@ Jimlam and @Keith. i done it with the change of single quotes to double quotes in this life of code.
from
$criteria->compare('CONCAT_WS(' ',first_name,last_name)',$this->client_name,true);
to
$criteria->compare('CONCAT_WS(" ",first_name,last_name)',$this->client_name,true);


Thanks for all .well done.
0

#8 User is offline   Jimlam 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 195
  • Joined: 17-March 12

Posted 20 November 2012 - 07:10 AM

Glad, it worked :)
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