开发者

Updating multiple rows in mysql with PHP

I have folliwing PHP file

which is creating this table:

Table createb by PHP with MySQL data

Every row have two inputs. My DB table has AUTO_INCREMENT 'ID' field.

How can I update my DB Table and make sure that rows will be updated accordingly to the ID's (auto incremented field)?

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?

            $news_SQLupdate = "UPDATE news SET ";   // table name is 'news'     
            $news_SQLupdate .=  "LIVE= '".$LIVE."', ";
            $news_SQLupdate .=  "CONTENT= '".$开发者_高级运维CONTENT."', ";
            $news_SQLupdate .=  "WHERE ID = '".$ID."' "; 


By including the id in the WHERE clause?

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


In your update statement, you will need a where id=(the id number)

Simple example:

UPDATE table_name set field1=value1 where id=1


UPDATE `tblContent` SET `On/Off` = true WHERE (`ID` = 1 OR `ID` = 2)

Dynamicaly add a OR ID = X in the where clause to apply the changes to another record.


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


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜