简体   繁体   English

使用PHP更新mysql中的多行

[英]Updating multiple rows in mysql with PHP

I have folliwing PHP file 我有PHP文件

which is creating this table: 这是创建此表:

Table createb by PHP with MySQL data 使用MySQL数据表格创建PHP

Every row have two inputs. 每行有两个输入。 My DB table has AUTO_INCREMENT 'ID' field. 我的数据库表有AUTO_INCREMENT'ID'字段。

How can I update my DB Table and make sure that rows will be updated accordingly to the ID's (auto incremented field)? 如何更新我的数据库表并确保行将根据ID(自动递增字段)进行相应更新?

I'm must admit that SQL with PHP is very new to me and I don't know is this correct way of doing it? 我必须承认使用PHP的SQL对我来说是一个新手,我不知道这是正确的做法吗?

            $news_SQLupdate = "UPDATE news SET ";   // table name is 'news'     
            $news_SQLupdate .=  "LIVE= '".$LIVE."', ";
            $news_SQLupdate .=  "CONTENT= '".$CONTENT."', ";
            $news_SQLupdate .=  "WHERE ID = '".$ID."' "; 

通过在WHERE子句中包含id?

UPDATE <someTable> SET ... WHERE id = <someId>

I tried this one state above: 我试过上面这个状态:

UPDATE table_name 
SET column_name1=' value[$array]', 
    column_name2=' value[$array]' 
WHERE column_name=' value[$array]' ; 

Just confirming that it worked for me perfectly. 只是确认它对我有用。

In your update statement, you will need a where id=(the id number) 在您的更新语句中,您将需要一个where id =(id号)

Simple example: 简单的例子:

UPDATE table_name set field1=value1 where id=1
UPDATE `tblContent` SET `On/Off` = true WHERE (`ID` = 1 OR `ID` = 2)

动态地在where子句中添加OR ID = X以将更改应用于另一个记录。

“UPDATE table_name SET column_name1 ='value [$ array]',column_name2 ='value [$ array]'WHERE column_name ='value [$ array]'”;

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

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