Hello everyone.
I need to update a value random generated(‘hash’) in some rows, only if the previous value was 0 and if another field is equal to the var $event. Everything works, but if I refresh the page, it overwrites one row of the loop. I wouldn’t expect that because there are no more rows with hash field equal to 0 ( I can see that in the phomyadmin ). It keeps on doing that as many times as the number of rows generated by the query are. I’m sure the problem is in the loop, but I can’t figure it out. Here the code:
$event= $_POST['event'];
$sql = "SELECT * FROM digital_orders where hash=0 and event='$event'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$key = uniqid(md5(rand()));
$id= $row["ID"];
$registerid = "UPDATE digital_orders SET hash='$key' where id='$id' " ;
$go = $conn->query($registerid) ;
}
}