Search code examples
phpmysqlauto-updatemultiple-columns

how to update multple rows in mysql with php


i have a table like this

id | website | ping |  online |
-------------------------------
1  |xxxx.com | 30   | 1
-------------------------------
4  |xxxx.com | 46   | 1
-------------------------------
5  |xxxx.com | 10   | 0
-------------------------------
8  |xxxx.com | 90   | 1
-------------------------------
11 |xxxx.com | 200  | 0

i want to know how to update the ping and the online rows in all the table without changing the id and website i already have the ping and the online functions


Solution

  • You are going to have to read the entire table, and then iterate through that recordset, getting the ID and using that to UPDATE the table with the new value for that ID.

    Something like (pseudocode)

    records = db.executeSQL("SELECT * FROM TABLE");
    foreach record in records
        $id = record.id
        $whateverping = the new ping for ID=$id
        $whateveronline = the new online for ID=$id
        result = db.executeSQL("UPDATE TABLE SET ping=$whateverping, online=$whateveronline WHERE ID=$id);