我试图更新数据库中选定的随机行,这是我的PHP代码
$offset_result = mysqli_query($conn, "SELECT FLOOR(RAND() * COUNT(*)) AS `offset` FROM `tbl_combi` WHERE `clear` = 0 ");
$offset_row = mysqli_fetch_object( $offset_result );
$offset = $offset_row->offset;
$result = mysqli_query($conn, "SELECT * FROM `tbl_combi` LIMIT $offset, 1");
$result_fetch = mysqli_fetch_array($result);
echo $result_fetch[1];
答案 0 :(得分:1)
您永远不会执行任何更新。这是你可以尝试的东西(它可能需要一些调整以满足你的需要):
$offset_result = mysqli_query($conn, "SELECT FLOOR(RAND() * COUNT(*)) AS `offset` FROM `tbl_combi` WHERE `clear` = 0 ");
$offset_row = mysqli_fetch_object( $offset_result );
$offset = $offset_row->offset;
$updateSql = 'UPDATE tbl_combi SET my_field="my_value" WHERE offset=' . $offset;
mysqli_query($conn, $updateSql);
$result = mysqli_query($conn, "SELECT * FROM `tbl_combi` LIMIT $offset, 1");
$result_fetch = mysqli_fetch_array($result);
echo $result_fetch[1];