Cake PHP
Cake PHP

Reputation: 163

How to search separated by comma value in cakephp

Need help in cakephp

I have a field furnished_details in a table and its content is below value (separated by comma). eg .

Double Bed,Flat TV : small (19"),Mirror,Extra storage,Window AC,Ceiling Fan,Lamp,Chair,Armoire,Mini-Fridge

Now in advanced search after submitting form, I store array value in a string separated by commas. eg .

TV,Bed,Linens Provided,Window AC,Ceiling Fan,Lamp,Chair,Armoire,Desk,Night stand,Extra storage

I just use

$conditions[]=array("MATCH(Room.furnished_details) AGAINST('$ame' IN BOOLEAN MODE)" );

but I don't get actual result .

Upvotes: 2

Views: 1223

Answers (2)

ADmad
ADmad

Reputation: 8100

User MySQL's FIND_IN_SET function.

Upvotes: 1

PoloRM
PoloRM

Reputation: 155

You want to search for several words (that are comma separated) inside a database field that contains other words that are comma separated? If I get it right, it's bound to get ugly.

The only way I can think of is to take your string, explode(',', $string), and then loop on this array to build a LIKE statement for each of your word.

I really advise to change your database structure though, why do you have a comma separated field for something that looks (to me) as if it should be a separate table altogether?

Upvotes: 0

Related Questions