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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.