I Have a MySQL database with a number of tables. One of these tables (composed of around 3000 rows) needs to be updated with a semi-complicated function that I've put together in PHP. Currently my solution is where I first read the desired column from the table, and then iterate through the column updating each value for each step:
$result = mysqli_query($con,"SELECT id, column1,column2 FROM $table");
$u=0; //Counter for loop
//Calculate value for each Row
if(mysqli_num_rows($result) > 0 ){
while($row = mysqli_fetch_assoc($result)){
$dataArray[] = $row ;
$dataArray[$u]['columnx'] = test_function($dataArray[$u]['column2']);
$id_des = $dataArray[$u]['id'];
$column1 = $dataArray[$u]['column1'];
$query11 = mysqli_query($con, "UPDATE $table SET $table.column1= ".$dataArray[$u]['column1']." WHERE id = $id_des;");
$u = $u+1;
}
}
Ive also done something similar with using a loop to build a very big Update Query, using a CASE clause, which is a little faster. Both methods however are very slow, and seem crude.
Note : The function used above is to convert a percentage to z score if thats any help.
Is there any way to do this without a loop or speed up execution? Even a single SQL statement perhaps ? Any help would be greatly appreciated.