所以我的表格包含“活动名称”“活动描述”“活动日期”和复选框“很重要”。当我检查复选框值“是”时,它重要,它将sql value =“1”发送到表“is_important”。一切都很好,但是我为“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
答案 0 :(得分:1)
这:
<tr<?php echo (($note['is_important'] == 1) ? "class='bg-danger'" : ""); ?>>
会渲染:
<trclass='bg-danger'>
如果is_important
为1.您需要在class
之前有空格。