日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

php 写 mysql 事件_PHP日歷,包含來自MySQL數據庫的重復事件

發布時間:2024/4/14 数据库 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php 写 mysql 事件_PHP日歷,包含來自MySQL數據庫的重復事件 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

9

In case anyone would like to do something similar, I will post the code that I wrote and tested within the last five hours.

如果有人想做類似的事情,我會發布我在過去五個小時內編寫和測試的代碼。

I decided to convert my two tables into three, moving all of the recurring options to the third table:

我決定將我的兩個表轉換為三個,將所有重復選項移動到第三個表:

'churchcal_events' - there are additional fields for event info that I haven't included here

'churchcal_events' - 我還沒有包含此事件信息的其他字段

+----+-----------+------------+------------+------------+-----------+

| id | name | date | starttime | endtime | recurring |

+----+-----------+------------+------------+------------+-----------+

| 1 | Event 1 | 2013-04-01 | 10:30:00 | 12:00:00 | 0 |

| 2 | Event 2 | | 14:00:00 | 15:00:00 | 1 |

| 3 | Event 3 | | 09:00:00 | | 1 |

| 4 | Event 4 | | 19:00:00 | 21:00:00 | 1 |

+----+-----------+------------+------------+------------+-----------+

'churchcal_assign' - routes events to appropriate calendars (because there will be calendars for different departments throughout the website)

'churchcal_assign' - 將事件路由到適當的日歷(因為整個網站的不同部門都會有日歷)

+----------+-------------+

| event_id | calendar_id |

+----------+-------------+

| 1 | 1 |

| 2 | 1 |

| 3 | 1 |

| 4 | 1 |

+----------+-------------+

'churchcal_recur_events' - Here are the rules for each event's recurrence

'churchcal_recur_events' - 以下是每個事件重復發生的規則

+----------+-----------+------------+----------------+------------+-------------+-----------+

| event_id | frequency | recur_type | recur_day_num | recur_day | recur_start | recur_end |

+----------+-----------+------------+----------------+------------+-------------+-----------+

| 2 | 1 | Week | NULL | Sunday | NULL | NULL |

| 3 | 2 | Week | NULL | Wednesday | 2013-04-01 | NULL |

| 4 | 2 | Month | third | Friday | 2013-04-01 | NULL |

+----------+-----------+------------+----------------+------------+-------------+-----------+

New Code (PHP) - This is in a day loop

新代碼(PHP) - 這是一天的循環

//query all events

$get_events = db_query("SELECT * FROM {churchcal_events ce, churchcal_recur_events cre}

WHERE (MONTH(ce.date) = :month AND YEAR(ce.date) = :year AND DAY(ce.date) = :day) OR

(ce.id = cre.event_id AND ce.recurring = :recur AND cre.recur_day = :calendar_day)

ORDER BY starttime",

array(

':month' => $month,

':year' => $year,

':day' => $list_day,

':recur' => '1',

':calendar_day' => date('l', strtotime($month . '/' . $list_day . '/' . $year)),

));

foreach($get_events as $event) {

//see if events belong to this calendar

$calendar_assign = db_query("SELECT * FROM {churchcal_assign} WHERE event_id = :event_id AND calendar_id = :cal_id",

array(

':event_id' => $event->id,

':cal_id' => $cal_id,

));

if($calendar_assign->rowCount() > 0) {

//one-time events

if(($event->recurring != '1') && ($single_event_id != $event->id)) {

$calendar .= calendar_event($event->id, $event->name, $event->starttime);

$single_event_id = $event->id;

//$calendar .= $single_event_id;

}

//monthly recurring events

if(($event->recur_type == 'Month') && ($event->recurring == '1')

//day is on or before end date

&& (($event->recur_end >= date('Y-m-d', strtotime($month . '/' . $list_day . '/' . $year))) || ($event->recur_end == '0000-00-00') || ($event->recur_end == NULL))

//day is on or after start date

&& (($event->recur_start <= date('Y-m-d', strtotime($month . '/' . $list_day . '/' . $year))) || ($event->recur_start == '0000-00-00') || ($event->recur_start == NULL))

//day is equal to date of recurrence, i.e. first friday, third monday, etc

&& ($year . date('m', strtotime($year . '/' . $month . '/' . $list_day)) . $list_day == date('Ymj', strtotime($event->recur_day_num . ' ' . $event->recur_day . ' of ' . date('F', strtotime($month . '/' . $list_day . '/' . $year)) . ' ' . $year)))

//day is in agreement with month frequency, i.e. every month, every other, etc. from start date

&& ($month % $event->frequency == date('m', strtotime($event->recur_start)) % $event->frequency)) {

$calendar .= calendar_event($event->id, $event->name, $event->starttime);

}

//weekly recurring events

if(($event->recur_type == 'Week') && ($event->recurring == '1')

//day is on or before end date

&& (($event->recur_end >= date('Y-m-d', strtotime($month . '/' . $list_day . '/' . $year))) || ($event->recur_end == '0000-00-00') || ($event->recur_end == NULL))

//day is on or after start date

&& (($event->recur_start <= date('Y-m-d', strtotime($month . '/' . $list_day . '/' . $year))) || ($event->recur_start == '0000-00-00') || ($event->recur_start == NULL))

//day is in agreement with week frequency, i.e. every week, every other, etc. from start date

&& (date('W', strtotime($month . '/' . $list_day . '/' . $year)) % $event->frequency == date('W', strtotime($event->recur_start)) % $event->frequency)) {

$calendar .= calendar_event($event->id, $event->name, $event->starttime);

}

}

}

If you are not creating this in a Drupal module like I am, you can replace 'db_query()' with your own database query function like PHP's default 'mysql_query()';

如果您不是像我一樣在Drupal模塊中創建它,您可以將'db_query()'替換為您自己的數據庫查詢函數,如PHP的默認'mysql_query()';

總結

以上是生活随笔為你收集整理的php 写 mysql 事件_PHP日歷,包含來自MySQL數據庫的重復事件的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。