php - Select and update the same row using while loop -
there looping query (while loop) select 2 column values table, code sums 2 values, need update column summed value> here code:
$stmt = $conn->prepare('select value1, value2, valuse3 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=? eg2.column=?"); $stmt1->bind_param('ii',$newvalue , $value3); $stmt1->execute(); }
when used queries got error: fatal error: call member function bind_param() on boolean in c:\xampp\htdocs\so\new\socialrank.php on line 13
if have solution achieve job using mysqli it's okay. appreciated, in advance.
i got solution. query same thing looking for:
$sql = ("update eg.table c1, eg.table c2 set c1.eg.column = (c2.value1 + c2.value2) c2.eg2.column = c1.eg2.column ");
note: solution inspired @cakephp answer
Comments
Post a Comment