php - 单元格的所有背景颜色都相同
问题描述
我正在为学生网创建学期地图。如果正在学习课程,则单元格颜色应为黄色。如果选课,应该是绿色的。如果课程尚未上课,单元格颜色将为红色。
我正在测试 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 有一个绿色背景,因为它已经被采用了。
解决方案
尝试如下:
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
}
推荐阅读
- c++ - Char 数组指针和“错误:'char []' 的初始化程序太多”
- javascript - 未定义未捕获的 ReferenceError 函数()
- c++ - 为什么不允许优化器在“恒定上下文”中折叠?
- arangodb - 写入速度差异
- selenium - AttributeError:“element_to_be_clickable”对象没有属性“click”python3.7
- javascript - 位智深度链接与多个位置?
- c# - 无法将数据从异步方法绑定到列表视图
- php - 如何 tro 翻译 Symfony 4 安全错误消息:“无效凭据”
- java - 在 java 11 http 客户端上运行 powermock + mockito
- eclipse - Eclipse Tricks and Tips 插件扩展点