【发布时间】:2020-01-31 21:03:07
【问题描述】:
我正在尝试使用切换开关更改 MySQL 文章表中 is_public 列的值。 如果我将输入(切换)包装在内部以使用 $_GET 方法在articles.php中进行必要的更改以获取记录的ID,那么它不会将is_public的数据获取到切换中。还有其他方法可以获取特定记录的 id 吗?
screenshot of the article list table
这是 all-articles.php 代码:
<table id="datatable" class="table table-hover" style="width:100%">
<thead>
<tr>
<th>#</th>
<th>Title</th>
<th>Author</th>
<th>Abstract</th>
<th>category</th>
<th>Date</th>
<th>Action</th>
<th>Publish</th>
</tr>
</thead>
<tbody>
<?php foreach($articles as $key => $article): ?>
<tr>
<td><?php echo $key+1 ?></td>
<td><?php echo $article['title'] ?></td>
<td><?php echo $article['author_id'] ?></td>
<td><?php echo $article['abstract'] ?></td>
<td><?php echo $article['category_id'] ?></td>
<td><?php echo $article['entry_date'] ?></td>
<td>
<div class="btn-group" role="group" aria-label="Basic example">
<button type="button" class="btn btn-primary btn-sm">Edit</button>
<button type="button" class="btn btn-success btn-sm">Show</button>
<button type="button" class="btn btn-danger btn-sm">Delete</button>
</div>
</td>
<td>
<form action="all-articles.php" method="post">
<label class="custom-toggle">
<?php if($article['is_public']): ?>
<input type="checkbox" checked name="check">
<?php else: ?>
<input type="checkbox" name="uncheck">
<?php endif; ?>
<span class="custom-toggle-slider rounded-circle"></span>
</label>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
【问题讨论】:
-
你需要更清楚一点,因为你想做什么??您是否希望能够单击某篇文章并能够在其他页面中对其进行编辑??\
-
@alithedeveloper 我想更改 MySQL 文章表中 is_public 列中的值,我的意思是当切换打开时,is_public 中的值更改为 1,如果它被关闭值应该更改为 0。为此,我需要获取该特定行/记录的 id。
-
文章表中是否包含primary key(例如
id)? -
@showdev 是的。