douqin2108 2016-05-14 21:15
浏览 86
已采纳

MySQL将随机行从一个表移动到另一个表

Is it possible to move a random row(with one column) to another table in that way so no one get this data even if will request it simultaneously?

For example: If you open my page, you get a data from MySQL that no one will get even if open this page simultaneously with you.

Now I do it this way:

mysql_query("INSERT INTO `ShowRow` SELECT * FROM `AllRows` WHERE 1 LIMIT 1");
mysql_query("DELETE FROM `AllRows` LIMIT 1");

Is it possible to do some another better way? Or how to SELECTsome specific row if there is only one column?

  • 写回答

2条回答 默认 最新

  • douzhouhan4618 2016-05-14 23:14
    关注

    Thank you to all, but I have come up to do it this way:

    $accCount = mysqli_query($connect, "SELECT * FROM AllRows");
    $accCount = mysqli_num_rows($accCount);
    $RandAcc = rand(0, $accCount);
    $result = mysqli_query($connect, "SELECT * FROM `AllRows`");
    $ReplaceRandAcc = mysqli_result($result, $RandAcc);
    
    mysqli_query($connect, "INSERT INTO `ShowRow` SELECT * FROM `AllRows` WHERE login='".$ReplaceRandAcc."'");
    mysqli_query($connect, "DELETE FROM `AllRows` WHERE login='".$ReplaceRandAcc."'");
    
    function mysqli_result($res, $row, $field=0) {
        $res->data_seek($row);
        $datarow = $res->fetch_array();
        return $datarow[$field];
    } 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 streamingtool
  • ¥15 MATLAB图像问题
  • ¥20 树莓派5做人脸情感识别与反馈系统
  • ¥15 selenium 控制 chrome-for-testing 在 Linux 环境下报错 SessionNotCreatedException
  • ¥15 使用pyodbc操作SQL数据库
  • ¥15 MATLAB实现下列
  • ¥30 mininet可视化打不开.mn文件
  • ¥50 C# 全屏打开Edge浏览器
  • ¥80 WEBPACK性能优化
  • ¥30 python拟合回归分析