【发布时间】:2017-05-09 11:59:59
【问题描述】:
这里我有两个表,我想根据手机号码从这两个表中写一个选择结果。
第一个表
新员工
staff_id firstName Mobile userType
1 Soupranjali 9986125566 Teacher
2 Sujata 8553880306 Teacher
第二张桌子
新学生
student_id first_Name fatherMobile user_type
1 janarthan 8553880306 Student
2 Santanu 8277904354 Student
这里 8553880306 两个表都可用,所以我需要这样的输出
预期结果
{
"status": "Success",
"Profile": [
{
"staff_id": "2",
"firstName": "Sujata",
"userType" : "Teacher"
},
{
"student_id": "1",
"firstName": "janarthan",
"user_type" : "Student"
},
]
}
如此尝试,但我无法得到答案,所以请任何人帮助我,
我的模特
public function android_memberList($mobile)
{
$this->db->select('new_staff.staff_id, new_staff.firstName, new_staff.userType, new_student.student_id, new_student.first_Name, new_student.user_type');
//$this->db->select('*');
$this->db->from('new_staff');
$this->db->join('new_student', 'new_student.fatherMobile = new_staff.Mobile');
$query = $this->db->get();
# result_array is used to convert the data into an array
$result = $query->result_array(); // or $result = $query->result_array()[0];
echo json_encode($query);
}
更新答案
[
{
"staff_id": "2",
"firstName": "Sujata",
"userType": "Teacher",
"student_id": "1",
"first_Name": "janarthan",
"user_type": "Student"
}
]
更新答案 2
[
[
{
"staff_id": "2",
"firstName": "Sujata",
"userType": "Teacher",
"student_id": "1",
"first_Name": "janarthan",
"user_type": "Student"
}
]
]
【问题讨论】:
-
打印出来(编辑你的问题)你有什么?有错误提示吗?
标签: php codeigniter model