gpt4 book ai didi

php - MySQL:通过创建的随机组增加ID

转载 作者:行者123 更新时间:2023-11-29 16:34:53 25 4
gpt4 key购买 nike

我希望我的表为每个创建的组自动增加一个 GroupId。这些组是从用户信息表中随机创建的。组信息表将随机组 ID(从 userInformation 表中选择)存储到其表中。到目前为止,我已经能够增加它。我只得到零

$GroupSize = $_POST['groupsize'];

//Connect to the Server+Select DB
$con = mysqli_connect($host, $user, $password, $dbName) or die("Nope");

if (isset($_POST['create'])) {

//assign group id to groups created
//insert groupinformation to table from userInformation


//What I Have Tried
//$query = "INSERT INTO groupInformation SELECT RegistrationId FROM (Select RegistrationId from userInformation order by RAND() LIMIT ".$GroupSize.")";
//$query = "INSERT INTO groupInformation(RegistrationId) SELECT RegistrationId FROM (Select * from userInformation order by RAND() LIMIT ".$GroupSize.") AS j";




$query = "INSERT INTO groupInformation(RandomGroupId,RegistrationId) SELECT randomRegistrationId,RegistrationId FROM (Select *,RAND() AS randomRegistrationId FROM userInformation ORDER BY randomRegistrationId LIMIT ".$GroupSize." ) AS j";
$result = mysqli_query($con, $query) or die ("query failed " . mysqli_error($con));



}

mysqli_close($con);

这是我的表格:

groupInformation

userInformation

这是我当前的输出:

output

我需要这些组有随机的 GroupId 来递增,例如 (1004 1003 1000) = 1(RandomGroupId), (1004, 1002, 1000) = 2(RandomGroupId), ...

最佳答案

试试这个方法。我希望它能帮助你:

$letters = 'abcefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';$verificationText =substr(str_shuffle($letters), 0, 10);

关于php - MySQL:通过创建的随机组增加ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53679147/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com