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.

    评论

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码