如何查找带有相应id的国家名称';s加入蛋糕


How to find countries name with their corresponding id's in cakephp join

在我的网站上,任何人都可以选择多个城市,他们的id会以逗号分隔进入数据库,但当加入cakepp查找国家名称时,我会如何查找所有国家名称。这是我在表中使用find("all")时收到的输出

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
            )
    )

这是我查找国家名称的cakepp查询

$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)')
 ),

我收到了我所做的空数组。请帮帮我。

最好的解决方案不是将国家列表存储在一个字段中,而是将数据结构标准化并存储在单独的记录中。

快速解决方案是在联接表达式中使用find_in_set()函数,与您所做的略有不同:

FIND_IN_SET(cu.id,job_posting_lists.job_loc_country)>0

必须删除cu.id=job_posting_lists.job_loc_country条件。