Jump to content

update multiple rows with random code


Canman2005

Recommended Posts

Unless you have a "where" clause on the query, this Update query will set all the rows to have the same value in the access field. Using the "where" clause will restrict the update to rows that match the "where" condition.

 

Ken

Even in a loop, you would still have to use the where clause. Do you have an auto increment field for each record or some other field that is unique for each record?

 

Here is an example if each record has a unique id field:

<?php
$q = "select id from people";
$rs = mysql_query($q);
while ($rw = mysql_fetch_assoc($rs)) {
    $uq = "update people set access = " . rand(1111,9999) . " where id = " . $rw['id'];
    $urs = mysql_query($uq);
}
?>

 

Note: untested, no error checking included in the code.

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.