哈罗,我的 table 在这里
sched_id sched_time sched_day emp_id
1 7:30-9:00 Monday 1
分别是主键、varchar(20)、varchar(20) 和一个外键。
我想在插入数据库中的特定数据时显示文本绿色,而在尚未插入时只显示普通的纯色。这是我到目前为止的工作
<?php
$sel_admin = " SELECT * from ehr_schedule where emp_id=".$_SESSION['emp_id']." ";
$rs_admin = mysql_query($sel_admin);
if($row = mysql_fetch_array($rs_admin))
{
?>
<td><?php if ($row['sched_stime']=="7:30-9:00")
{ ?>
<span style="color:green">7:30-9:00</span> //I have already the specific requirement and data in my database, and this display nicely
<?php } ?>
7:30-9:00 //Although, I want this to be hidden when the requirement above is meeted
<?php } ?> </td>
最佳答案
您需要使用 and else
来逆向出现 if
。所以:
<?php if ($row['sched_stime']=="7:30-9:00")
{ ?>
<span style="color:green">7:30-9:00</span> //I have already the specific requirement and data in my database, and this display nicely
<?php } else {?>
7:30-9:00
<?php } ?>
您可以在此处阅读有关 else
的更多信息,http://php.net/manual/en/control-structures.else.php .
所以它几乎是:
if (..) {
condition was met, this block executes;
} else {
condition was not met, this block executes;
}
或者你可以使用 else if
,如果你想检查多个东西。
关于php,mysql,html,css - 当有数据库数据时隐藏特定文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37929135/