如果该字段gp_categories
包含字符串“12 56 34 345 349”,我如何找到包含数字 34 的记录?
$id = 34;
// 1. Works but is there a more efficient way?
$q['conditions']['OR'] = array(
array('Groups.gp_categories LIKE' => $id), // Only
array('Groups.gp_categories LIKE' => $id.' %'), // Start
array('Groups.gp_categories LIKE' => '% '.$id.' %'), // Middle
array('Groups.gp_categories LIKE' => '% '.$id) // End
);
// 2. Finds either 34, 345, 349 etc
$q['conditions'] = array('Groups.gp_categories LIKE' => '%'.$id.'%');