-4

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

  • This question does not show any research effort. It is important to **do your homework**. Tell us what you found and ***why*** it didn't meet your needs. This demonstrates that you've taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer. [FAQ](http://stackoverflow.com/questions/how-to-ask). – John Conde Apr 18 '13 at 15:49
  • http://dev.mysql.com/doc/refman/5.0/en/update.html – jcho360 Apr 18 '13 at 15:51
  • i know the update Syntax but i dont know how to update the whole table because the IDs are not successive – user2295756 Apr 18 '13 at 15:53
  • @user2295756 - would you add your UPDATE statement to the question? – andrewsi Apr 18 '13 at 16:24

1 Answers1

0

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);
Laurence Moroney
  • 1,263
  • 8
  • 20