显示 mysql 表中的所有行,然后提供删除特定行的选项
我希望能够显示数据库表中的所有条目,并且每个条目都使用户能够删除特定的条目。
我目前正在使用 for every 循环,该循环循环显示每个条目的数据库。
$result = mysql_query("SELECT * FROM KeepScores");
$fields_num = mysql_num_fields($result);
echo "<table><tr>";
// printing table headers
echo "<td>Recent Posts</td>";
echo "</tr>\n";
// printing table rows
while($row = mysql_fetch_row($result))
{
echo "<tr>";
// $row is array... foreach( .. ) puts every element
// of $row to $cell variable
foreach($row as $cell)
echo "<td>$cell</td>";
echo "</tr>\n";
}
如何添加每个出现的删除按钮并从数据库表中删除该条目?
I want to have the ability to show all the entries in a database table and by each one give the user the ability to delete specific ones.
I am currently using a for each loop that loops through the database showcasing each entry.
$result = mysql_query("SELECT * FROM KeepScores");
$fields_num = mysql_num_fields($result);
echo "<table><tr>";
// printing table headers
echo "<td>Recent Posts</td>";
echo "</tr>\n";
// printing table rows
while($row = mysql_fetch_row($result))
{
echo "<tr>";
// $row is array... foreach( .. ) puts every element
// of $row to $cell variable
foreach($row as $cell)
echo "<td>$cell</td>";
echo "</tr>\n";
}
How would to add a delete button that appears by each one and removes the entry from the database table?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用表单来完成:
//main.php
//delete.php:
或者您可以使用 jQuery 和 AJAX 来完成:
//main.php
//delete.php
这一切都未经测试,并且肯定需要针对您的特定项目进行一些调整,但我认为您明白了,我希望它有所帮助。
下次,如果您询问有关数据库的问题,请发布您的架构。
You can do it with forms:
//main.php
//delete.php:
Or you can do it with jQuery and AJAX:
//main.php
//delete.php
It's all untested and sure needs some adjustment for your specific project, but I think you get the idea and I hope it helps.
Next time, please post your schema if you ask stuff about database.
我想我可以通过将删除帖子包装在类和函数中来对此进行一点改进。我也遇到了同样的问题。这对我来说非常有用。再次感谢@Quasdunk
I thought I would improve on this a little bit by wrapping the delete post in a class and function. I was having the same problem. and this worked great for me. Thanks again @ Quasdunk
使用 jquery 为每个表生成一个密钥,然后将其链接到一个 php 文件,该文件接受密钥并从特定表中删除(也可以通过 jquery 传递)
Produce a key to each table, using jquery,then link it to a php file which an accept the key and delete from the specific table (which also can be passed through jquery)