Php 如何在codeigniter中根据手机号码从两个表中获取结果
这里我有两个表,我想根据手机号码从这两个表中选择一个结果 第一桌 新教职员 第二桌 新生 这里8553880306两个表都可用,所以我需要这样的输出 预期结果 所以像这样试过,但我无法得到答案,所以请任何人帮助我 我的模型 更新的答案Php 如何在codeigniter中根据手机号码从两个表中获取结果,php,codeigniter,model,Php,Codeigniter,Model,这里我有两个表,我想根据手机号码从这两个表中选择一个结果 第一桌 新教职员 第二桌 新生 这里8553880306两个表都可用,所以我需要这样的输出 预期结果 所以像这样试过,但我无法得到答案,所以请任何人帮助我 我的模型 更新的答案 [ { "staff_id": "2", "firstName": "Sujata", "userType": "Teacher", "student_id": "1", "first_Name": "jana
[
{
"staff_id": "2",
"firstName": "Sujata",
"userType": "Teacher",
"student_id": "1",
"first_Name": "janarthan",
"user_type": "Student"
}
]
更新答案2
您需要检查两个表上移动列的数据类型 它们必须具有相同的数据类型才能执行联接操作。您可以尝试此操作
public function android_memberList($mobile)
{
$this->db->select('new_staff.staff_id, new_staff.firstName, new_staff.userType, new_student.student_id, new_student.firstName, 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($result);
}
当您使用result\u array
时,它将作为零索引数组出现。您可以选择它,也可以使用上面代码的注释将其删除
是的,我在BIGINT中给出的两个表数据类型您能检查我在这两个表中的select查询是否正确吗?在我的查询中,我没有给mobile numberty在查询后使用$this->db->last\u query()打印您的查询。我可以用phpmyadmin查找记录。当我在
staff
手机上打印查询选择*FROMnew\u staff
asstaff
加入new\u student
asstudent
时,我得到了这个查询。如果你有正确的数据类型,你会得到结果。打印(编辑你的问题)你得到了什么?有任何错误消息吗@Abdulla Nilam先生,我尝试了你的代码,请检查我的更新答案,我得到了类似的答案,一些不需要的值在提交如何删除that@subikshanM使用此$this->db->select('new_staff.staff_id,new_staff.firstName,new_staff.userType,new_student.student_id,new_student.firstName,new_student.user_type');
您似乎错过了这个$result=$query->result_array()
和这个echo json\u encode($result)
我改变了,但我还是得到了相同的答案,一些不需要的值也出现在你的答案中
{
"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"
}
]
[
[
{
"staff_id": "2",
"firstName": "Sujata",
"userType": "Teacher",
"student_id": "1",
"first_Name": "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.firstName, 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($result);
}