加入两个表并将其显示在表中

时间:2015-10-08 06:05:23

标签: php codeigniter

enter image description here

我有两个表“rps_users”包含名为id,membership_no,volunteer_name和email的列,“rps_volunteer_score”包含volunteer_id,registration_assessor,interviewer,professional_registration_advisor和registration_category。这里的id和volunteer_id相同。志愿者出现在“rps_users”表在“rps_volunteer_score”表中的不同“registration_category”下有多条记录。 我想显示一个包含会员号,志愿者姓名,电子邮件和类型的表。 “类型”记录基于“rps_volunteer_score”records.ie发现,

if( $interviewer!="" && $interviewer <= 4 )echo "Interviewer";
if($registration_assessor !="" && $registration_assessor >= 2 && $registration_assessor <= 4 )echo "Assessor";
if($registration_assessor !="" && $registration_assessor >= 3 && $registration_assessor <= 4)echo "Moderator";
if($registration_assessor !="" && $registration_assessor = '4' ) echo "Registrar";
if($professional_registration_advisor !="" && $professional_registration_advisor= '1')echo "PRA";

我用它来加入两个表

public function get_volunteers_list($condition)
{

    $this->db->select("u.id,u.membership_number,u.family_name,u.first_name,u.email_address, vs.registration_assessor, vs.interviewer,vs.professional_registration_advisor");
    $this->db->from(self::$tbl_name . " as u");
    $this->db->join(Volunteer_score::$tbl_name . " as vs", "u.id = vs.volunteer_id","left");
    $this->db->where($condition);
    $query = $this->db->get(); 
    //var_dump($this->db->last_query());
    return $query->result();
}

但是我得到了一位志愿者的多条记录。 请帮我找一个解决方案。 这是控制器代码。

    $volunteer_list = $this->Users->get_volunteers_list(array("u.staff"=>'N'));
    var_dump($volunteer_list);
    $this->data["volunteer_list"] = $volunteer_list;

1 个答案:

答案 0 :(得分:1)

您应该按membership number

进行分组

get()

之前添加此行
$this->db->group_by("u.membership_number");