Codeigniter如何在不重复数据的情况下连接多个表

时间:2018-07-22 20:27:14

标签: php codeigniter view

我有一张与工作,技能和教育有一对多关系的候选人表...

我想显示所有可以显示类似这样的内容

候选人姓名1  -求职者1  -求职者2  -候选人技能1  -候选人技能2  -候选人教育1 候选人姓名2  -求职者3    求职者4    候选人技能3    候选人技能4    候选人教育2    候选人教育3

反正有这样做吗?

这是我的代码

public function get_all_candidates_info(){

    $this->db->select('*');        // select all columns
    $this->db->from('candidates'); // FROM table
    $this->db->join('work_experiences', 'work_experiences.candidate_id = candidates.id','left'); // INNER JOIN
    $this->db->join('skills', 'skills.candidate_id = candidates.id','left'); // INNER JOIN
    $this->db->join('educations', 'educations.candidate_id = candidates.id','left'); // INNER JOIN
    $query = $this->db->get(); // GET RESULT

    $result = $query->result_array();

    //return $result;



    $newArray = array();
    foreach ($result as $key => $value) {
        $newArray[$value['first_name']."asdasds"][] = $value; // sort as per candidate name
    }


    foreach ($newArray as $key => $value) {
    echo $key."<br/>"; // print Category Name
    foreach ($value as $final_value) {

        echo $final_value['skill_name']."<br/>"; // print all items against category
         echo $final_value['education_provider']."<br/>"; // print all items against category
          echo $final_value['company_name']."<br/>"; // print all items against category

    }
}

0 个答案:

没有答案