在我的网站上,任何人都可以选择多个城市,他们的ID以逗号分隔进入数据库,但是当你加入cakephp查找国家名称时,我如何找到所有国家名称。这是我在使用find时收到的输出(表
中的所有')Array
(
[0] => Array
(
[job_posting_lists] => Array
(
[id] => 1
[firm_id] => 1
[job_title] => Software Engineer
[number_opening] => 10
[job_details] => American Express is embarking
[keyword] => java,Hadoop
[min_work_exp] => 1
[max_work_exp] => 3
[currency] => S$
[ctc_from] => 10000
[ctc_to] => 15000
[other_ctc_details] => Incentives
[job_loc_country] => 101,123,45,56
[job_loc_state] =>
[job_loc_city] =>
[select_industry] => 4
[skill] => 1
[key_skill_name] => 13
[designation] => 18
[job_type] => Full time
[ug_qualification] => 1,11
[ug_stream] => Computer
[pg_qualification] => 2
[docterate] => Ph.D
[reference_code] => 0
[reference_name] =>
[added_on] => 2016-04-18 12:15:58
[slug] => software-engineer
[status] => 0
[verify] => 0
)
)
这是我的cakephp查询,以查找国家/地区名称
$requests = $this->job_posting_lists->find('all', array('joins' => array(
array(
'table' => 'countries',
'alias' => 'cu',
'type' => 'inner',
'foreignKey' => false,
'conditions'=> array('cu.id = job_posting_lists.job_loc_country','FIND_IN_SET(cu.id,job_posting_lists.job_loc_country)')
),
我收到的是我做的空数组。请帮忙。
答案 0 :(得分:0)
最佳解决方案不是将国家/地区列表存储在单个字段中,而是将数据结构规范化并将其存储在单独的记录中。
快速解决方案是在连接表达式中使用find_in_set()函数,与您的操作略有不同:
FIND_IN_SET(cu.id,job_posting_lists.job_loc_country)>0
必须删除cu.id = job_posting_lists.job_loc_country标准。