Jump to content

Recommended Posts

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.