单元格的所有背景色都相同

时间:2019-04-12 02:46:50

标签: php html mysql sql

我正在为学生网络创建一个学期地图。如果正在上课,则单元格颜色应为黄色。如果采取该路线,则应为绿色。如果尚未完成课程,则单元格颜色将为红色。

我正在测试ID为“ 1”的学生,在“ course_status”表中有一个名为“ course_status”的列,其中只有“ pending”,“ in_progress”和“ done”。

$sql = "SELECT * FROM course_status WHERE student_id = 1";
$retval = mysqli_query( $link, $sql );
$row=mysqli_fetch_array($retval);
if($row['course_status']== 'done') {$status_color = "green";}
if($row['course_status']== 'in_progress') {$status_color= "yellow";}
if($row['course_status']== 'pending') {$status_color= "red";}
<td style="background-color: <?php echo $status_color; ?>;">CSCI 185 
<td style="background-color: <?php echo $status_color; ?>;">CSCI 385 
<td style="background-color: <?php echo $status_color; ?>;">CSCI 485 

尽管该学生尚未参加CSCI 385&485,但所有单元的背景色均为绿色。我只希望CSCI 185自拍摄以来具有绿色背景。

1 个答案:

答案 0 :(得分:0)

尝试如下:

if($row['course_status']== 'done') {

<td style="background-color:green">something</td>//bg-color will be green

}else if($row['course_status']== 'in_progress'){

<td style="background-color:yellow">something</td>//bg-color will be yellow

} else {
<td style="background-color:red">something</td> //bg-color will be red

}