如何获取表中特定记录的id-PHP
我试图使用切换开关更改MySQL文章表中is_public列的值。 如果我将输入(切换)封装在里面,使用$\u get方法获取记录的id,以便在articles.php中进行必要的更改,那么它不会将is\u public的数据提取到切换中。是否有其他方法获取特定记录的id 这是all-articles.php代码:如何获取表中特定记录的id-PHP,php,mysql,toggle,Php,Mysql,Toggle,我试图使用切换开关更改MySQL文章表中is_public列的值。 如果我将输入(切换)封装在里面,使用$\u get方法获取记录的id,以便在articles.php中进行必要的更改,那么它不会将is\u public的数据提取到切换中。是否有其他方法获取特定记录的id 这是all-articles.php代码: <table id="datatable" class="table table-hover" style="width:100%"&
<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>
#
标题
著者
摘要
类别
日期
行动
出版
编辑
显示
删去
好吧,你可以将文章id发送到你的表单中,然后收听它并用它做你想做的事情。所以
// As you are already in foreach loop so,
<form action="all-articles.php" method="post">
<label class="custom-toggle">
<?php if($article['is_public']): ?>
<input type="checkbox" checked name="published" value="<?php echo $article['id']; ?>>
<?php else: ?>
<input type="checkbox" name="published" value="<?php echo $article['id']; ?>>
<?php endif; ?>
<span class="custom-toggle-slider rounded-circle"></span>
</label>
</form>
你需要更清楚一点,你想做什么??你想点击某篇文章并在其他页面编辑它吗?\@alithedeveloper我想更改MySQL文章表中is_public列的值,我的意思是当切换打开时,is_public中的值将更改为1,如果关闭,值应更改为0。为此,我需要获取该特定行/记录的id。articles表是否包含(例如,
id
)?@showdev是的。
// As you are already in foreach loop so,
<form action="all-articles.php" method="post">
<label class="custom-toggle">
<?php if($article['is_public']): ?>
<input type="checkbox" checked name="published" value="<?php echo $article['id']; ?>>
<input type="hidden" name="is_published" value="yes"> or 1
<?php else: ?>
<input type="hidden" name="is_published" value="no"> or 0
<input type="checkbox" name="published" value="<?php echo $article['id']; ?>>
<?php endif; ?>
<span class="custom-toggle-slider rounded-circle"></span>
</label>
</form>