PHP select不返回值

问题描述:

I have this code and I want to get the info in medication table and display it where acc_id in account table is = to acc_id in medication table and where 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);
    }

}

this is my ts :

how can I do that ?

Thank you in advance!

我有这段代码,我想在药物表 code>中获取信息并显示 其中帐户表 code>中的 acc_id code>是 = code>到 accicid code> drug table code>和 med_timeoftheday ='morning' code> p>

  $ postdata = file_get_contents(“php:// input”); 
if(isset($ postdata)){\  n $ request = json_decode($ postdata); 
 $ User_ID = $ request-> acccid; 
 $ sql = sprintf(“SELECT * FROM account_info 
 join drug on account_info.acc_id = medication.acc_id 
其中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); 
} 
 
 \  n} 
  code>  pre> 
 
 

这是我的问题: p>

我该怎么做? p>

提前谢谢! p> div>

Try somehting like this:

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

firstly if you selected data from medication table so select first medication table and then using join with account table .

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