PHP select不会返回值

时间:2017-12-11 17:52:34

标签: php mysql ionic2

我有这段代码,我希望在medication table中获取相关信息并将acc_id account table中的= acc_id medication table显示在med_timeoftheday='morning' {} 1}}和$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); } }

{{1}}

这是我的意思:

我该怎么做?

提前谢谢!

2 个答案:

答案 0 :(得分:1)

试试这样的话:

SELECT * FROM medication 
  INNER JOIN account_info ON account_info.acc_id = medication.acc_id
WHERE medication.med_timeoftheday='morning'

答案 1 :(得分:0)

首先,如果您从药物表中选择数据,请选择第一个药物表,然后使用帐户表连接。

$sql = "SELECT * FROM medication JOIN account_info ON account_info.acc_id = medication.acc_id WHERE medication.med_timeoftheday='morning'";