![](/img/trans.png)
[英]PHP - How to store an arrays keys in an array and use it to later access the value
[英]query a mysql table for rows that have the same month value and store as a php array for later use displaying them on a calendar
該主題基本上將其總結出來,但是我正在為客戶端的php開發日歷,該客戶端應該從表中提取事件並在適當的單元格中顯示它們。
日歷表沒有問題,但我要避免的是每月的每一天進行單獨的數據庫調用。
我試圖首先找到一種將結果存儲在數組數組中的方法,然后在創建日歷時,每天都有一個事件的事件將顯示該事件的某些數據,即使在那里也是如此。
這是我遇到的概念性問題,我似乎無法解決。
另外,不確定是否可行。
任何幫助表示贊賞。
謝謝。
例如:
select day, title, desc where month = $month and year = $year order by day asc
並最終輸出類似這樣的內容而不會命中數據庫31次:
day1.
title / desc
day2.
title / desc <br>
title / desc
day3.
title / desc
您可以執行一次查詢以獲取此Mounth中的所有事件,
就像你寫
select day, title, desc from mytable
where month = $month and year = $year order by day asc
並在結果的foreach循環中,將其存儲在數組中,例如
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$events[$row['day']][] = $row;
}
因此,在循環結束時,您將獲得數組$ events,其中每個條目都包含當天的事件數組。
如$events[1], $events[2] ....
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.