0
<?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 :)

  • 2
    so do some `if()` work, set a `$color`, and then embed that in your html. and...``? in 2016? – Marc B Jul 12 '16 at 13:48
  • @MarcB and `mysql_*`? in 2016? xD – FirstOne Jul 12 '16 at 13:49
  • 1
    Do not set the color within the html tag. Use css classes instead. Your css classes could be the "status" itself. This will lead to html like This is the status. Using css you can give this class whatevver color you want. – user1915746 Jul 12 '16 at 13:51

1 Answers1

1

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.