Yii Framework Forum: Add Condition problem - Yii Framework Forum

Jump to content

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

Add Condition problem Rate Topic: -----

#1 User is offline   neel 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 133
  • Joined: 08-October 09

Posted 25 March 2010 - 09:48 AM

Hey Guys
I have one problem .
$criteria->addCondition('telephone LIKE'. $_GET['tel']. '%');
this addCondition is not working

public function view()
{
$criteria=new CDbCriteria;
$criteria->addCondition('telephone LIKE'. $_GET['tel']. '%');

return new CActiveDataProvider('Contact', array(
'criteria'=>$criteria,

));
}
0

#2 User is offline   lgoss007 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 88
  • Joined: 01-October 09

Posted 25 March 2010 - 10:19 AM

Looks like there is no space between LIKE and the value.. is there? Are you debugging the output?

Also you can do the same thing by doing:
$criteria->compare('telephone', $_GET['tel'], true);

0

#3 User is offline   Dana 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 203
  • Joined: 18-February 10
  • Location:Florida, USA

Posted 25 March 2010 - 10:21 AM

Pardon me if this is just a transcription error in pasting here, but it looks like you have a whitespace/quotes error in your condition:

View PostNeel, on 25 March 2010 - 09:48 AM, said:

Hey Guys
I have one problem .
$criteria->addCondition('telephone LIKE'. $_GET['tel']. '%');
this addCondition is not working

public function view()
{
$criteria=new CDbCriteria;
$criteria->addCondition('telephone LIKE'. $_GET['tel']. '%');

return new CActiveDataProvider('Contact', array(
'criteria'=>$criteria,

));
}


should read as (note the space after LIKE):
$criteria->addCondition('telephone LIKE '. $_GET['tel']. '%');


and assuming you're on a MySQL backend, you also need to use quotations when comparing strings, so it's actually going to be
$criteria->addCondition('telephone LIKE `'. $_GET['tel']. '%`');

otherwise it will look for a column name that matches your $_GET['tel']% string.
0

#4 User is offline   neel 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 133
  • Joined: 08-October 09

Posted 25 March 2010 - 10:22 AM

View Postlgoss007, on 25 March 2010 - 10:19 AM, said:

Looks like there is no space between LIKE and the value.. is there? Are you debugging the output?

Also you can do the same thing by doing:
$criteria->compare('telephone', $_GET['tel'], true);


I want to match first 6 digit. is that possible
0

Share this topic:


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

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users