我正在开发一个网页,其中包含一个在加载页面时动态填充的表格。我在表的每一行都有一个删除/更新按钮,但我无法弄清楚如何获取所选表行的值(消息ID),以便我可以在正确的记录上运行删除/编辑脚本。
这是填充表格的代码:
while ($row=mysqli_fetch_array($run_post)){
$post_date=$row['msg_post_date'];
$post_title=$row['msg_title'];
$post_id=$row['msg_id'];
$post_list[]=$row['msg_id'];
//table post date
echo "<td><div class='thumbnail-mar-less'>$post_date</div></td>";
//table title
echo "<td><div class='thumbnail-mar-less'><a href='#'>$post_title</a></div></td>";
//table buttons
echo "<td>
<form class='form-inline thumbnail-mar-less' role='form'>
<div class='form-group'><button class='btn btn-default btn-sm'>Edit Post</button></div>
<div class='form-group'><button name='delete'value=' ' class='btn btn-primary btn-sm'>Delete</button></div>
</div>
</td>";
echo "</tr>";
}
有关如何为每行分配和检索值的任何建议???
答案 0 :(得分:0)
您的表单没有&#34;操作&#34;,因此它将提交给&#34;当前&#34;网址自动。 如果当前网址与处理PHP的表单页面相同,则可以。 您的表单没有结束标记,因此,其余部分可能在页面上看起来很奇怪。
如bobdye和SimonMᶜKenzie指出的那样,您应该在表单中包含$post_id
值的字段。
尝试这样的事情:
echo '
<form class="some fancy classes" action="some_handler.php">
<input type="hidden" value="'.$post_id.'">
<input type="submit" value="go!">
</form>
';