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 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services