当有数字< 6 时,将另一个表格中的单元格变为红色



我正在建立一个自行车预订系统。它将从表单中获取信息并将其放入数据库(完成(在数据库之后,信息将进入一个表(完成(。借出时间结束后(未完成(,该信息也将被删除在另一张表2中,我记录了我们借出的自行车。现在我想让我的代码读取借出的自行车,并将编号为红色的单元格变为红色。当编号为空的单元格需要变为绿色。

当它读取响应表中发生的事情时,我不知道如何更改表2中的单元格。希望有人能帮我。

<!DOCTYPE html>
<html>
<head>
<title>Bike Waiver</title>
<!-- <link rel="stylesheet" type="text/css" href="mtb.css"> -->
<!- head elements (Meta, title, etc) -->
<!-- Link your php/css file -->
<link rel="stylesheet" href="mtb.php" media="screen">
</head>
<body>

<br>
<?php

echo "<table style='border: solid 1px black;'>";
echo "<tr>
<th>bike1</th> 
<th>bike2</th> 
<th>bike3</th> 
<th>bike4</th> 
<th>bike5</th> 
<th>bike6</th>
<th>Firstname</th> 
<th>Lastname</th> 
<th>hotel</th> 
<th>roomNumber</th> 
<th>email</th> 
<th>startDate</th>
<th>startTime</th>
<th>returnDate</th>
<th>endTime</th>
<th>returnPlace</th>
<th>numberBike</th> 
<th>numberHelmet</th> 
<th>numberPumps</th> 
</tr>";
class TableRows extends RecursiveIteratorIterator {
function __construct($it) {
parent::__construct($it, self::LEAVES_ONLY);
}
function current() {
return "<td style='width: 150px; border: 1px solid black;'>" . parent::current(). "</td>";
}
function beginChildren() {
echo "<tr>";
}
function endChildren() {
echo "</tr>" . "n";
}
}
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "mtb";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT bike1, bike2, bike3, bike4, bike5, bike6, first_name, last_name, hotel, roomNumber, email, startDate, startTime, returnDate, endTime, returnPlace, numberBike, numberHelmet, numberPumps FROM mtbtable");
$stmt->execute();

// set the resulting array to associative
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
echo $v;
}
}
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
$conn = null;
echo "</table>";

?>
<br>
<?php

echo "<table style='border: solid 1px black;'>";
echo "<tr>
<th>bike1</th> 
<th>bike2</th> 
<th>bike3</th> 
<th>bike4</th> 
<th>bike5</th> 
<th>bike6</th>
<th>Firstname</th> 
<th>Lastname</th> 
<th>hotel</th> 
<th>roomNumber</th> 
<th>email</th> 
<th>startDate</th>
<th>startTime</th>
<th>returnDate</th>
<th>endTime</th>
<th>returnPlace</th>
<th>numberBike</th> 
<th>numberHelmet</th> 
<th>numberPumps</th>  
</tr>";
class TableRows2 extends RecursiveIteratorIterator {
function __construct($it) {
parent::__construct($it, self::LEAVES_ONLY);
}
function current() {
return "<td style='width: 150px; border: 1px solid black;'>" . parent::current(). "</td>";
}
function beginChildren() {
echo "<tr>";
}
function endChildren() {
echo "</tr>" . "n";
}
}

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "mtb";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT bike1, bike2, bike3, bike4, bike5, bike6, first_name, last_name, hotel, roomNumber, email, startDate, startTime, returnDate, endTime, returnPlace, numberBike, numberHelmet, numberPumps FROM mtbtable");
$stmt->execute();
// set the resulting array to associative
$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) {
echo $v;
}
}
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
$conn = null;
echo "</table>";
?>
<br>
<table>
<tr>
<th>Number of bike</th> 

</tr>
<tr>
<td class="td<?php echo $openColor; ?>" >1</td>
</tr>
<tr>
<td>2</td>

</tr>
<tr>
<td>3</td>

</tr>
<tr>
<td>4</td>

</tr>
<tr>
<td>5</td>

</tr>
</table>


</body>
</html>

您可以为此使用三元运算符。

<td class="<?=  $isBikeLent ? 'bg-danger' : 'bg-success' ?>" >1</td>

如果$isBikeLent是一个"truthy"值,则第一部分将运行"bg危险",否则为"bg成功"。

缩写<?= ... ?>将自动回显字符串,这是<?php echo ... ?>的缩写

相关内容

最新更新