开发者

HTML Table row edit/Delete

开发者 https://www.devze.com 2023-01-13 02:54 出处:网络
I have an HTML table with contents, I would like to have an feature of Edit/Delete to that table. How do I do开发者_运维技巧 it with PHP? I actually think that this sounds more like a job for JavaScri

I have an HTML table with contents, I would like to have an feature of Edit/Delete to that table. How do I do开发者_运维技巧 it with 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. (Implement some AJAX too, and you can edit/remove rows in database too).

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.


Well, there is a pure PHP way to do it, and then there is a combination of Javascript and 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).

If using just PHP, you must generate HTML documents for each change. E.g., 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; 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). Here's a tutorial for how to do this: 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. 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

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. When you have enough knowledge of SQL, look at PHP's PDO extension: http://php.net/manual/en/book.pdo.php

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号