我有这段代码,我想在medication table
中获取信息并将其显示在account table
中的acc_id
=
以medication table
acc_id
的位置以及med_timeoftheday='morning'
$postdata = file_get_contents("php://input");
if (isset($postdata)) {
$request = json_decode($postdata);
$User_ID = $request->acccid;
$sql = sprintf("SELECT * FROM account_info
join medication on account_info.acc_id = medication.acc_id
where account_info.acc_id='%s'",
mysqli_real_escape_string($conn,$User_ID));
$result=$conn->query($sql);
if ($result->num_rows>0)
{
while($row=$result->fetch_assoc())
{$data[]=$row;
}
echo json_encode($data);
}
}
这是我的 TS :
我该怎么做?
提前谢谢你!
尝试这样操作:
SELECT * FROM medication
INNER JOIN account_info ON account_info.acc_id = medication.acc_id
WHERE medication.med_timeoftheday='morning'
首先,如果您从药物表中选择了数据,请选择第一个药物表,然后使用与客户表连接。
$sql = "SELECT * FROM medication JOIN account_info ON account_info.acc_id = medication.acc_id WHERE medication.med_timeoftheday='morning'";