douqixia7942 2016-07-12 13:46
浏览 65

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

<?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);
?>

That is my JSON file. I want to change the event color of my fullcalendar. I have certain conditions related to reservation approval. For example, if it's already approved, the event will change into color blue from red which is pending. Your answers are highly appreciated. Thank you :)

  • 写回答

1条回答 默认 最新

  • duanmei1946 2016-07-12 13:58
    关注

    As suggested by @MarcB, you need an if and a $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>'
                        );
    }
    

    As you have read in the comments, it's time to stop using mysql and change to mysqli (or PDO) and start using CSS classes.

    评论

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算