JSON中的PHP if-else条件用于更改fullcalendar中的事件颜色

时间:2016-07-12 13:46:29

标签: php json if-statement fullcalendar-scheduler

<?php
header("Access-Control-Allow-Origin: *");
header('Content-type:application/json');

mysql_connect('localhost','root','') or die(mysql_error());

mysql_select_db('pmothesis');

$select = mysql_query("SELECT * FROM venue_reservations join venue on venue.venue_code = venue_reservations.venue_code join office on office.office_id = venue_reservations.office_id where status != 'Finished'");

$rows = array();

while ($row = mysql_fetch_array($select))
{
    $rows[] = array('id'=>$row['venue_reservation_id'],
                    'title'=>$row['venue_name'],
                    'start'=>$row['date_time_start'],
                    'end'=>$row['date_time_end'],
                    'description'=>"Purpose: ".$row['purpose'].
                    ' <br> Venue reservation id: ' .$row['venue_reservation_id'].
                    ' <br> Event type: ' .$row['event_type'].
                    ' <br> Number of persons: ' .$row['number_of_persons'].
                    ' <br> Office name: ' .$row['office_name'].
                    ' <br> <br> Status: <font style="color: red;"> ' .$row['status']. ' </font>'
                    );
}



echo json_encode($rows);
?>

这是我的JSON文件。我想更改fullcalendar的事件颜色。我有一些与预订批准有关的条件。例如,如果它已被批准,则事件将从待处理的红色变为蓝色。非常感谢您的回答。谢谢:))

1 个答案:

答案 0 :(得分:1)

根据@MarcB的建议,您需要if$color

while ($row = mysql_fetch_array($select))
{   if ( $row['status'] == "approved" )     //<========= CHECK STATUS HERE.
         $color = "blue";
    else $color = "red";
    $rows[] = array('id'=>$row['venue_reservation_id'],
                    'title'=>$row['venue_name'],
                    'start'=>$row['date_time_start'],
                    'end'=>$row['date_time_end'],
                    'description'=>"Purpose: ".$row['purpose'].
                    ' <br> Venue reservation id: ' .$row['venue_reservation_id'].
                    ' <br> Event type: ' .$row['event_type'].
                    ' <br> Number of persons: ' .$row['number_of_persons'].
                    ' <br> Office name: ' .$row['office_name'].
                    ' <br> <br> Status: <font style="color: ' . $color . ';"> ' . //<========= COLOR VARIABLE.
                    $row['status']. ' </font>'
                    );
}

正如您在评论中所读到的,现在是时候停止使用mysql并更改为mysqli(或PDO)并开始使用CSS类。