Select and update the same row using while loop

There is a looping query (while loop) to select 2 column values from a table, then the code sums the 2 values, what I need is to update another column with the summed value>
Here is the code:

$stmt = $conn->prepare('select value1, value2, valuse3  from  eg.table limit ? ');
$stmt->bind_param('i',$limit);
$stmt->execute();
$stmt->bind_result($value1, $value2,$value3);
$arr = array();
while($stmt->fetch()) {
$row = array();
array_push($arr, $row);
$newvalue=($value1+$value2);

$stmt1 = $conn->prepare("UPDATE eg.table SET eg.column=? WHERE  eg2.column=?");
$stmt1->bind_param('ii',$newvalue , $value3);
$stmt1->execute();
}

When I used this queries I got this error: Fatal error: Call to a member function bind_param() on boolean in C:xampphtdocssonewsocialrank.php on line 13

If you have another solution to achieve the job using Mysqli it’s okay.
Any help will be appreciated,
Thanks in advance.


Source: oop

Leave a Reply