更新同一行MySQL上的多个列

时间:2021-03-09 13:17:53

I couldn't find a definite answer to this specific issue, basically what I have created is a HTML table which displays the contents of a database into columns and rows. Currently it is very simple as I am understanding how it works for now.

我找不到这个特定问题的明确答案,基本上我创建的是一个HTML表格,它将数据库的内容显示为列和行。目前它很简单,因为我现在理解它是如何工作的。

ID | First_Name | Last_Name | Bio | Created

ID = Primary Key for each row of the database.

ID =数据库每一行的主键。

I wish to be able to update an entire row of the database with one update command, if this is possible. Currently I am using:

我希望能够使用一个更新命令更新数据库的整行,如果可能的话。目前我正在使用:

$sql = "UPDATE databasetest.people SET First_Name = '".htmlspecialchars($_POST['FirstName'])."' WHERE people.ID = ".$_POST['edit'];

...where $_POST['FirstName'] is the first name, as defined by a form and $_POST['edit'] is the ID as defined by an initial form where the user selects "Edit User".

...其中$ _POST ['FirstName']是第一个名称,由表单定义,$ _POST ['edit']是由初始表单定义的ID,用户选择“编辑用户”。

Is it possible to update multiple columns (first name, last name, bio and created at once) in this way?

是否可以通过这种方式更新多个列(名字,姓氏,生物和一次创建)?

EDIT: Very quick answers, thank you very much! I am not sure why I was downvoted, possibly because it was dumb? Sorry, still learning :)

编辑:非常快速的答案,非常感谢你!我不确定为什么我被投票,可能是因为它是愚蠢的?对不起,还在学习:)

1 个解决方案

#1


You want

  UPDATE table
     SET col='val', col2='val2', col3=123
   WHERE ID = 345

See how you can use commas to separate multiple columns and the values they should get?

了解如何使用逗号分隔多个列以及它们应该获得的值?

#1


You want

  UPDATE table
     SET col='val', col2='val2', col3=123
   WHERE ID = 345

See how you can use commas to separate multiple columns and the values they should get?

了解如何使用逗号分隔多个列以及它们应该获得的值?