Jump to content

Is There An Easier To Do UPDATE?


steviemac

Recommended Posts

I have about 350 rows that I have to update a single column in each row.  I coded so I can do each row individually but I was wondering if there is a way to update all of them at once.  Hence saving me time.

 

This is my code:

<?PHP
include "dbmembers.php";
?>
<?php 

if(isset($submit)){
$ID = mysql_real_escape_string(trim($_POST['ID']));

$result = mysql_query("SELECT response FROM myuser WHERE ID ='$ID'");
$row = mysql_fetch_array($result);
$res = hash("sha256", $row['response'] .$salt  );
{
echo $row['response'] ."----".$res;

echo "<br /><br />"; }
}
mysql_query("UPDATE myuser SET response='$res' WHERE ID = '$ID'");
printf ("Updated records: %d\n", mysql_affected_rows());

?>

 

Thanks in advance for any advise.

Link to comment
Share on other sites

If you have mysql 5.5.5 (where sha2 was added to mysql), you could do everything in a single UPDATE query.

 

For your existing code, since you need to use php to preform the sha256 hash, you would need to select each value, modify it using php code, and then update the value.

 

You are aware that you could automate this by forming a select query that gets all the rows and then iterate over all the rows to modify and update the values? There's no need to have any sort of form that submits one id at a time.

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.