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!

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'";