0
我需要得到明智例如結果行作爲日期結果行,我有PHP的MySQL如何獲得在datewise
prs_id date desc
1 2015-07-10 Test data1
2 2015-07-10 Test data2
3 2015-07-11 Test data3
med_id prs_id drug dosage
1 1 Pracetamol 3
2 1 calpol 4
3 2 crocin 5
4 3 xxxxxx 8
我需要形成陣列並需要顯示像下面
2015-07-10
1 Test data1
1 1 Pracetamol 3
2 1 calpol 4
2 Test data2
3 3 crocin 5
2015-07-11
3 Test data3
4 3 xxxxxx 8
我嘗試以下代碼
$sql = "SELECT * from prescriptions";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$answer[$row['prs_created_date']][] = $row;
}
}
以下代碼簡單地打印陣列,與處方數據作爲密鑰,叔這就是Marc B。但我需要打印作爲預期的表格,我該怎麼做。
echo '<pre>';
print_r($answer);
'$ answer [$ row ['date']] [] = $ row;' –
Brilliant,Thanks Marc B,I got the solution – user3929758