简体   繁体   English

HTML表格行编辑/删除

[英]HTML Table row edit/Delete

I have an HTML table with contents, I would like to have an feature of Edit/Delete to that table. 我有一个包含内容的HTML表,我想具有对该表进行编辑/删除的功能。 How do I do it with PHP? 我该如何使用PHP?

I actually think that this sounds more like a job for JavaScript, which can edit/remove rows on-the-fly and with much less code. 我实际上认为,这听起来更像是JavaScript的工作,它可以实时编辑/删除行,而只需更少的代码。 (Implement some AJAX too, and you can edit/remove rows in database too). (也实现一些AJAX,您也可以编辑/删除数据库中的行)。

But if you insist on using PHP, you might just want to add some GET parameters to the Edit/Delete links that would delete or edit those rows. 但是,如果您坚持使用PHP,则可能只想向“编辑/删除”链接添加一些GET参数即可删除或编辑这些行。

Well, there is a pure PHP way to do it, and then there is a combination of Javascript and PHP. 嗯,有一种纯PHP的方法可以做到这一点,然后有Javascript和PHP的组合。 You must use PHP one way or another if you want your changes to the database to be permanent as that is your gateway to communicating with the database (as far as I know you cannot do that with Javascript as that is client-based and runs entirely in your web browser). 如果要永久保留对数据库的更改,则必须以一种或另一种方式使用PHP,因为这是与数据库进行通信的网关(据我所知,您不能使用Javascript进行此操作,因为Javascript是基于客户端的并且完全可以运行在您的网络浏览器中)。

If using just PHP, you must generate HTML documents for each change. 如果仅使用PHP,则必须为每次更改生成HTML文档。 Eg, you click on one cell in the table and that gets you to a new HTML page where the field is editable through an input element; 例如,您单击表中的一个单元格,然后转到新的HTML页面,在该页面中可以通过input元素来编辑该字段; or you can list all fields at once for that row and edit them all at the same time. 或者您可以一次列出该行的所有字段,然后同时对其进行全部编辑。 The fields are then posted in a form to a PHP page which will take the new values and update the database (or insert new values or however you wish it to behave). 然后将这些字段以表单的形式发布到PHP页面,该页面将采用新值并更新数据库(或插入新值,或者您希望它表现出来)。 Here's a tutorial for how to do this: http://www.freewebmasterhelp.com/tutorials/phpmysql/1 这是有关如何执行此操作的教程: http : //www.freewebmasterhelp.com/tutorials/phpmysql/1

You can also mix in some Javascript which allows a more interactive interface to modifying the values in a cell. 您还可以混入一些Javascript,该Javascript允许使用更具交互性的界面来修改单元格中的值。 However, this obviously requires more code and may be overkill for what you're trying to do. 但是,这显然需要更多代码,并且可能对您尝试执行的操作过大。 Nonetheless, here is a link which demonstrates just that and also shows the code: http://www.java2s.com/Code/JavaScript/GUI-Components/Editabletablecell.htm 但是,这里有一个链接演示了这一点,并显示了代码: http : //www.java2s.com/Code/JavaScript/GUI-Components/Editabletablecell.htm

Hope this is what you're looking for. 希望这是您想要的。

EDIT: Forgot that you also wished to delete content in the table. 编辑:忘记了您也希望删除表中的内容。 That is also explained in the first link. 在第一个链接中也对此进行了说明。

If you intend to work with databases, and it seems like you have little understanding of how they work, pick up a good book like: SQL - The Complete Reference . 如果您打算使用数据库,而您似乎对数据库的工作方式几乎一无所知,请选择一本不错的书,例如: SQL-The Complete Reference When you have enough knowledge of SQL, look at PHP's PDO extension : http://php.net/manual/en/book.pdo.php 当您对SQL有足够的了解时,请查看PHP的PDO扩展http : //php.net/manual/zh/book.pdo.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM