我希望我的表为每个创建的组自动增加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);
这是我的桌子:
这是我当前的输出:
我需要这些组具有随机的GroupId来递增,例如(1004 1003 1000)= 1(RandomGroupId),(1004、1002、1000)= 2(RandomGroupId),...
答案 0 :(得分:0)
尝试这种方式。我希望它将对您有帮助:
$ letters ='abcefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'; $ verificationText = substr(str_shuffle($ letters),0,10);