<?php //连接数据库 $mysqli = new mysqli("localhost", "root", "root123456", "hrms"); if ($mysqli->connect_errno) { die("连接失败: " . $mysqli->connect_error); } //查询日程 $result = $mysqli->query("SELECT * FROM event"); $events = array(); while ($row = $result->fetch_assoc()) { $event = array(); $event['id'] = $row['id']; $event['title'] = $row['title']; $event['start'] = $row['start']; $event['end'] = $row['end']; $event['status'] = $row['status']; $events[] = $event; } //返回JSON格式数据 echo json_encode($events); ?>修改代码块,使status值为pending的数据用灰色显示在html页面
时间: 2023-08-31 12:40:05 浏览: 129
您可以通过在生成事件数组时检查 "status" 值,并根据其值设置相应的 CSS 类来实现此目的。以下是修改后的代码块:
```php
<?php
//连接数据库
$mysqli = new mysqli("localhost", "root", "root123456", "hrms");
if ($mysqli->connect_errno) {
die("连接失败: " . $mysqli->connect_error);
}
//查询日程
$result = $mysqli->query("SELECT * FROM event");
$events = array();
while ($row = $result->fetch_assoc()) {
$event = array();
$event['id'] = $row['id'];
$event['title'] = $row['title'];
$event['start'] = $row['start'];
$event['end'] = $row['end'];
$event['status'] = $row['status'];
// 根据 status 值设置 CSS 类
if ($row['status'] === 'pending') {
$event['className'] = 'pending-event';
}
$events[] = $event;
}
//返回JSON格式数据
echo json_encode($events);
?>
```
上述代码中,我们检查 "status" 值是否为 "pending",如果是,则将 "className" 设置为 "pending-event"。在 HTML 页面中,您可以使用 CSS 样式表来定义 "pending-event" 类,以实现灰色显示。
阅读全文