所以我的表格由“事件名称”“事件描述”“事件日期”和复选框“重要”组成。当我选中复选框值“yes”时,它会发送到表“is_important”的sql值=“1”。一切都很好,但我为“is_important”= 1 表提供了引导样式“bg-danger”,但它没有显示。有什么问题? 代码中可以看到:
<?php
if (isset($_POST['important'])) {
$error = array();
$success = array();
$eventTime = time();
$important = $_POST['important'];
$eventName = trim(mysql_real_escape_string($_POST['EventName']));
$eventDesc = htmlentities(trim(mysql_real_escape_string($_POST['EventDesc'])), ENT_QUOTES);
if (!isset($eventName) || empty($eventName)) {
$error['eventName'] = "Prasome ivesti ivykio varda";
} else if (strlen($eventName) > 32 || strlen($eventName) < 3) {
$error['eventName'] = "Ivykio pavadinimas turi buti tarp 3 ir 32 simboliu";
}
if (!isset($eventDesc) || empty($eventDesc)) {
$error['eventDesc'] = "Prasome ivesti ivykio aprasyma";
}
if (empty($error)) {
$sql = "INSERT INTO notes_list (title, description, timestamp,is_important) VALUES ('$eventName', '$eventDesc','$eventTime','$important')";
$result = mysqli_query($con, $sql);
$success[] = "SEKME !";
} else {
}
}
?>
<table class="table table-striped">
<thead>
<tr>
<th>Event name</th>
<th>Event description</th>
<th>Event date</th>
</tr>
</thead>
<tbody>
<?php
$query = "SELECT * FROM notes_list ORDER BY id DESC LIMIT 10";
$result2 = mysqli_query($con, $query);
print_r($_POST);
if ($result2) {
while ($note = mysqli_fetch_assoc($result2)) {
?>
<tr<?php echo (($note['is_important'] == 1) ? "class='bg-danger'" : ""); ?>>
<td><?php echo $note['title']; ?></td>
<td><?php echo $note['description'] ?></td>
<td><?php echo date('l M jS', $note['timestamp']); ?></td>
</tr>
<?php
}
mysqli_free_result($result2);
}
/* close connection */
mysqli_close($con);
?>
</tbody>
</table>
这张图片中的完整示例: https://www.dropbox.com/s/h650h2spy2487dm/chechbox.jpg?dl=0
最佳答案
这个:
<tr<?php echo (($note['is_important'] == 1) ? "class='bg-danger'" : ""); ?>>
会渲染这个:
<trclass='bg-danger'>
如果 is_important
为 1。您需要在 class
之前有一个空格。
关于php - 选中复选框时如何为 SQL 表提供样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25887447/