即時通訊使用JQuery完整日曆事件。我知道到目前爲止沒有一個選項可以通過限制來加載事件。JQuery完全日曆限制事件與PHP
在月視圖中,如果我一天有100個事件,它會使表單元格變得非常大。我想限制它每天10個事件。
我想我會做的是在服務器端使用PHP來做到這一點。由於在給定日期範圍的情況下使用PHP加載所有事件,我以爲我會一天一天地加載並將其限制爲每天10個事件。
這就是我對PHP的一面:
if ($currView == 'month') //curr view is the current view of the calendar
{
$start = $_GET['start']; //gets from the calendar usually start of month
$end = $_GET['end']; //gets from calendar usually end of month
//some array to store all events before using json_encode
$limitEvents = array();
$limit = 10;
//loop through from start till end by 1 day incremental
for ($i = $start; $i < $end; $i+=strtotime($i, "+1 day"))
{
//make the end of day to be the current day but 23:59:59
$endOfDay = date('m/d/Y', $start);
$endOfDay = strtotime($endOfDay . ' 23:59:59');
//load the events from DB using date range which is 1 day and limit of events
$loaded = $this->loadDataFromDB($start, $endofDay, $limit);
//merge the arrays
array_merge($limitTasks, $loaded);
}
}
現在有了這個代碼的問題是,它不是最佳的,當我嘗試運行它,它遍歷每一天,每天的查詢和需要很長時間,它甚至超時。
我的問題是,我怎麼會在MySQL端做這個?我會給出從月初到月底的日期範圍。而不是每天循環PHP邊和每天加載數據,我會在MySQL方面做到這一點。例如查詢將看起來像什麼:
SELECT *
FROM Events_Table
WHERE Ev_Date BETWEEN :startMonth AND :endMonth
(have extra query to load by days within given start and end month
and have LIMIT 10 per day)
不能完成上面的查詢中,括號中的文字需要有效的查詢被轉移,以便可以選擇每天10個事件,並有31天,以便它應該選擇大約310個事件
如果有人有更好的解決方案,請幫助。
查詢的哪一部分給你帶來麻煩:每天限制爲10或者開始和結束邊界的where子句? – jimbojw
它不給我麻煩,我無法完成查詢,以便它選擇每天10個事件,並有31天,所以它應該選擇約310個事件 – Giorgi
你是否在意你按時間順序獲得前10名?或者只是你在給定的一天中得到的不超過10個? – jimbojw