sanfly Posted May 19, 2012 Share Posted May 19, 2012 Hi I have two fields in my users table: first_name & last_name I want to be able search by name (first or last or first & last) to return a result eg: lets say I have Joe Bloggs and Joe Jenkins If I search 'Joe' i get both back (thats fine) If I search 'Bloggs' I just get Joe Bloggs back (also fine) But if I search 'Joe Bloggs' I dont get the correct results back, I guess because its looking firstly in first_name and then in last_name This is my request for this search $u = $this->User->find('all', array('conditions' => array( "OR" => array( 'User.first_name LIKE ' => "%" . trim($input) . "%", 'User.last_name LIKE ' => "%" . trim($input) . "%", ) ) )); I have an awful feeling this could get really complicated with exploding the input into arrays and nested requests? Anyone have any ideas - especially ones that will keep it uncomplicated Link to comment https://forums.phpfreaks.com/topic/262794-cakephp-searching-like-in-two-fields/ Share on other sites More sharing options...
jcombs_31 Posted May 27, 2012 Share Posted May 27, 2012 What if you concat first and lastname? Link to comment https://forums.phpfreaks.com/topic/262794-cakephp-searching-like-in-two-fields/#findComment-1349000 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.