2016-12-07 43 views
0

房間預訂時是否可能使顏色變紅?我不知道當我想要改變顏色時,我應該如何處理if語句。我目前只是sql2,但我不知道該怎麼做。所有的幫助表示讚賞。如何根據預訂更改td的顏色?

function fDisplayARoomSection($date){ 
global $servername, $password, $dbname, $username; 

//connect to the database---------- 
$conn = mysqli_connect($servername, $username, $password, $dbname); 
if (!$conn) { 
    die ("Connection failed: " . mysqli_connect_error()); 
} 

//Prepare the SQL statement and send it to the database 
$sql = "SELECT * FROM rooms "; 
$result = mysqli_query($conn, $sql); 

//Loop through the resulting set of records 

while($row = mysqli_fetch_assoc($result)) { 
    echo "<div style=\"background-color:AliceBlue;\">"; 
    echo "<hr style=\"\">"; 
    echo "<p style=\"margin-bottom:.1em;margin-top:.1em;\"><a href=\"\">Room: " .$row["RoomNumber"] ."</a></p>"; 
    echo "<table style=\"border-collapse:collapse;border-spacing:0;\">"; 

    //-- display hours 
    echo "<tr>\n"; 
     for ($c=1;$c<=10;$c++){ 
    echo "<td colspan=\"4\" class=\"Hours\">" .(7+$c) ."</td>\n"; 
     } 
    echo "</tr>"; 
    $sql2 = "SELECT * FROM bookings WHERE bookingRoomID=" .$row["RoomID"] ." bookingDate='" .$date ."'"; 
    //--display timeline 
    echo "<tr>"; 
      if ($sql2){ 
       $color="red"; 
      }else{ 
       $color="white"; 
      } 
     echo "<td class=\"Timeline\" style=\"background-color:$color; "; 
      if ($c==1){echo "border-left:1px solid black;";}  
       if ($c%4==0){echo "border-right:1px solid black;";} 
        echo "\"></td>\n"; 
     } 

    echo "</tr></table>"; 
    echo "<hr style=\"\">"; 
    echo "</div>"; 


} 
+0

檢查書室中while循環。 – Rajkeshar

+0

我該怎麼做?我是新手編程 –

+0

在哪個表中您將存儲預訂的房間數據 – Rajkeshar

回答

0

您需要使用來自SQL2 mysql_fetch_field結果集中檢查Column值。您可以檢查該值併爲條件格式添加條件。

0

變化是這樣的:

echo '<td class="Timeline" style="background-color:'.$color.';';