mysql:通过创建的随机组递增id

8yoxcaq7  于 2021-06-18  发布在  Mysql
关注(0)|答案(1)|浏览(297)

我希望我的表为创建的每个组自动增加一个groupid。这些组是从userinformation表中随机创建的。组信息表将随机组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);

这是我的table:


这是我的电流输出:

我需要组有random groupid来递增,比如(1004 1003 1000)=1(randomgroupid),(1004 1002,1000)=2(randomgroupid)。。。

wvyml7n5

wvyml7n51#

这样试试。我希望它能帮助你:
$letters='efghijklmnopqrstuvxyzdefghijklmnopqrstuvxyz1234567890'$verificationtext=substr(str\u shuffle($letters),0,10);

相关问题