I'm using cakePHP 2.3 to build an application with a restaurant database. Now, the person before me has saved restaurant details in a table called 'locations' which has a row for cuisine which has multiple values in one column, like 1 location can have chinese, indian, korean etc.
If the column has values stored like this "north indian,chinese,mughlai",I want that non adjacent cuisines should be searchable too...like if i receive "'north indian' 'mughlai'" in the posted data, it should still show even though there's chinese in between. Basically is there a command to select multiple partial values from a string in the column?
Please help!
<?php
$saved="north indian,chinese,mughlai";
$search="north indian, mughlai";
foreach(explode(",",$search) as $keyword)
{
$keyword=trim($keyword);
if(stristr($saved,$keyword)!==false)
{
echo "Match Found for $keyword <br>";
}
}
?>
You will need to create a conditions array entry for each cuisine using LIKE as the comparison operator. This builds on Hanky Panky's example
$conditions = array();
foreach (explode(",", $search) as $keyword)
{
$keyword=trim($keyword);
$conditions[] = "columnname LIKE '%" . $keyword . "%'";
}
Then your find is:
$this->Location->find('all', array('conditions' => $conditions));