this is my first post, so be gentle :)
这是我的第一个帖子,所以要温柔一些
I am brand new to PHP, MySQL, and JQUERY, but I have a lot of experience programming with AS3, Java, and C++, so I have some frame of reference to how some of this stuff works...
我是PHP、MySQL和JQUERY的新手,但是我有很多经验编程,有AS3、Java和c++,所以我有一些关于这些东西如何工作的参考框架。
Here's what I'm trying to do:
下面是我想做的:
- I am creating a website for my church and using the Fullcalendar class for our scheduler
- 我正在为我的教堂创建一个网站,并为我们的调度器使用Fullcalendar类。
- Note: Google Calendar is not an option
- 注意:谷歌日历不是一个选项。
- I need to be able to set recurring events, and color each event based on whether or not it has been canceled
- 我需要能够设置重复的事件,并根据是否被取消而将每个事件的颜色设置为颜色。
Here's how far I've gotten:
这是我得到的结果:
- I have a MySQL database with 8 fields: p_id (for my use only), id, title, start, end, allDay, url, canceled
- 我有一个MySQL数据库,有8个字段:p_id(仅供我使用),id, title, start, end, allDay, url,取消。
- I have a PHP file with the following code:
- 我有一个PHP文件,有以下代码:
.
。
//--------------------------------------------------------------------------
// Example php script for fetching data from mysql database
//--------------------------------------------------------------------------
$host = "fakehost";
$user = "fakeuser";
$pass = "fakepwd";
$databaseName = "fake_db";
$tableName = "tbl_calendar";
//--------------------------------------------------------------------------
// 1) Connect to mysql database
//--------------------------------------------------------------------------
$con = mysql_connect($host,$user,$pass);
$dbs = mysql_select_db($databaseName, $con);
//--------------------------------------------------------------------------
// 2) Query database for data
//--------------------------------------------------------------------------
$query = "SELECT id,title,start, DATE_FORMAT(start, '%Y-%m-%d %H:%i' ) AS startDate, end, url FROM $tableName ORDER BY startDate DESC";
$result = mysql_query($query) or die(mysql_error());
$array = array();
while($row = mysql_fetch_assoc($result)){
$array[] = $row;
}
//--------------------------------------------------------------------------
// 3) echo result as json
//--------------------------------------------------------------------------
echo json_encode($array);
?>
-
I also have the following code in my HTML file:
我的HTML文件中也有以下代码:
<script type='text/javascript'> $(document).ready(function() { var date = new Date(); var d = date.getDate(); var m = date.getMonth(); var y = date.getFullYear(); $('#calendar').fullCalendar({ header: { left: 'prev,next today', center: 'title', right: 'month,agendaWeek,agendaDay' }, editable: false, allDayDefault: false, url: true, timeFormat: 'h(:mm)t', // uppercase H for 24-hour clock agenda: 'h(:mm)t' , // 5:00 - 6:30 '': 'h(:mm)t', // for all other views events: "../data/get_calendar.php", eventDrop: function(event, delta) { alert(event.title + ' ha sido movido ' + delta + ' dias\n' + '(should probably update your database)'); }, loading: function(bool) { if (bool) $('#loading').show(); else $('#loading').hide(); }, eventClick: function(calEvent, jsEvent, view) { //alert('Event: ' + calEvent.title); //alert('Url: ' + calEvent.url); //alert('View: ' + view.name); window.open(calEvent.url, blank); return false; } }); });
It all works great as far as using the events I have in the database and placing them on the calendar where they belong.
在使用数据库中的事件并将它们放置在它们所属的日历上时,这一切都很好。
The problem is that I'm trying to add specific CSS classes to each event. I would like canceled events to be Red, for example (versus deleting them).
问题是,我正在尝试为每个事件添加特定的CSS类。我希望取消事件是红色的,例如(而不是删除它们)。
I have looked through a lot of material. Read a lot about event sources and I just don't get it... I can't make it work. Ideally, I'd like to add another field to my database and just have it apply a class name or color automatically. I can apply colors through hard code, but I just don't understand how to do it through the database.
我看过很多资料。读很多关于事件来源的文章,我就是不明白。我做不到。理想情况下,我希望在我的数据库中添加另一个字段,并让它自动应用类名或颜色。我可以通过硬编码来应用颜色,但是我不知道如何通过数据库来实现。
Can anyone help? Please give me a lot of simple steps, because apparently, I'm not that smart :-S
谁能帮忙吗?请给我一些简单的步骤,因为很明显,我没那么聪明:-S。
EDIT: I have tried to add a field called "className" and I've written corresponding CSS rules. I thought that would do it, but when I inspect the element, I don't see the className anywhere... I don't think it's applying it automatically from the MySQL database. I also tried Brotherli's suggestion below, but can't get that to work either (probably user error). Perhaps I need to change some of my fullcalendar jquery code?
编辑:我尝试添加一个名为“className”的字段,并编写了相应的CSS规则。我以为会这样做,但当我检查元素时,我看不到任何地方的类名……我不认为它是从MySQL数据库中自动应用的。下面我也尝试了姐弟的建议,但也不能让它发挥作用(可能是用户错误)。也许我需要更改我的一些fullcalendar jquery代码?
1 个解决方案
#1
0
You can define CSS classes on a per-event basis. See attribute 'className' in http://arshaw.com/fullcalendar/docs/event_data/Event_Object/
可以在每个事件基础上定义CSS类。在http://arshaw.com/fullcalendar/docs/event_data/Event_Object/中查看属性'className'。
Change your PHP code to something like
将PHP代码更改为类似的内容。
while($row = mysql_fetch_assoc($result)){
if ($row['deleted'])
$row['className'][] = 'deleted';
if ($row['canceled'])
$row['className'][] = 'canceled';
$array[] = $row;
}
Alternatively you can also add CSS classes on the client using the eventRender callback.
或者,您也可以使用eventRender回调在客户机上添加CSS类。
#1
0
You can define CSS classes on a per-event basis. See attribute 'className' in http://arshaw.com/fullcalendar/docs/event_data/Event_Object/
可以在每个事件基础上定义CSS类。在http://arshaw.com/fullcalendar/docs/event_data/Event_Object/中查看属性'className'。
Change your PHP code to something like
将PHP代码更改为类似的内容。
while($row = mysql_fetch_assoc($result)){
if ($row['deleted'])
$row['className'][] = 'deleted';
if ($row['canceled'])
$row['className'][] = 'canceled';
$array[] = $row;
}
Alternatively you can also add CSS classes on the client using the eventRender callback.
或者,您也可以使用eventRender回调在客户机上添加CSS类。