我目前有一个 PHP 表单,它使用 AJAX 连接到 MySQL 并显示与用户选择匹配的记录 (AJAX:显示带有多个选择框值的 MySQL 数据)
除了显示数据之外,我还在每个结果旁边放置了一个“编辑”按钮,该按钮显示一个表单,其中数据可以编辑。我的问题是编辑唯一记录,因为目前我仅使用“姓名”和“年龄”的选定值来查找记录。如果两个(或更多)记录具有相同的姓名和年龄,我只能编辑第一个结果。
I currently have a PHP form that uses AJAX to connect to MySQL and display records matching a user's selection (AJAX: Display MySQL data with value from multiple select boxes)
As well as displaying the data, I also place an 'Edit' button next to each result which displays a form where the data can be edited. My problem is editing unique records since currently I only use the selected values for 'name' and 'age' to find the record. If two (or more) records share the same name and age, I am only able to edit the first result.
发布评论
评论(2)
假设您的编辑文件是 edit.php。然后,在生成编辑链接的文件中,尝试更改编辑按钮链接,如下所示:
然后你将能够访问 ID 变量
请注意,ID 区分大小写。让我知道进展如何。
Let's assume your file for editing is edit.php. Then, in the file where you generate the edit links, try changing your edit button link as follows:
Then you will be able to access ID variable as
Note that the ID is case sensitive. Let me know how it goes.
当显示来自ajax的记录时,还发送主字段(大多数情况下为id)以及姓名和年龄
,当您显示这些数据并进行编辑时,将主字段与编辑合并起来
when displaying records from ajax, also send the primary field(id in most cases) along with name and age
and when u are displaying these data along with edit incorporate that primary field with edit