Php mySQL:为double select查询分配自动递增ID号
我正在创建一个程序,其中我从一个表中选择的数据被随机分组。来自每个组的RegistrationID号作为外键保存到另一个表中,并且每个组成员都被分配一个groupID,该groupID随创建的每个新组自动递增Php mySQL:为double select查询分配自动递增ID号,php,mysql,phpmyadmin,Php,Mysql,Phpmyadmin,我正在创建一个程序,其中我从一个表中选择的数据被随机分组。来自每个组的RegistrationID号作为外键保存到另一个表中,并且每个组成员都被分配一个groupID,该groupID随创建的每个新组自动递增 $GroupSize = $_POST['groupsize']; //Connect to the Server+Select DB $con = mysqli_connect($host, $user, $password, $dbName) or die("Nope"); if
$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
$query = "SELECT RegistrationId FROM (Select * from userInformation order by RAND() LIMIT ".$GroupSize.") INTO groupInformation";
$result = mysqli_query($con, $query) or die ("query failed" . mysqli_error($con));
//display group and information
echo "<table border='1' >";
echo "<tr><th>RegId</th><th>Name</th><th>Address</th><th>Email</th></tr>";
while (($row = mysqli_fetch_row($result)) == true) {
echo "<tr><td>$row[0]</td><td>$row[1]</td><td>$row[2]</td><td>$row[3]</td></tr>";
}
echo "</table>";
//if group is less than 2 create error message
}
mysqli_close($con);
这是我的表格
让GroupId自动递增,然后在groupInformation中再创建一列RandomGroupId,然后粘贴查询:
INSERT INTO groupInformation(RandomGroupId,RegistrationId)
SELECT randomRegistrationId,RegistrationId
FROM (Select *,RAND() AS randomRegistrationId
FROM userInformation ORDER BY randomRegistrationId LIMIT ".$GroupSize."
) AS j
让GroupId自动递增,然后在groupInformation中再创建一列RandomGroupId,然后粘贴查询:
INSERT INTO groupInformation(RandomGroupId,RegistrationId)
SELECT randomRegistrationId,RegistrationId
FROM (Select *,RAND() AS randomRegistrationId
FROM userInformation ORDER BY randomRegistrationId LIMIT ".$GroupSize."
) AS j
我获取{query failed Undeclared variable:groupInformation}尝试将此插入到groupInformation中选择RegistrationId FROM SELECT*FROM userInformation order by RAND LIMIT.$GroupSize。作为jIf,如果您只需要单列,请尝试将此插入groupInformationRegistrationId从SELECT*中选择RegistrationId从userInformation按兰德限制排序。$GroupSize。作为jSorry,您的两个屏幕截图属于同一个表。很抱歉,请尝试将此插入到groupInformationGroupId、RegistrationId选择randomRegistrationId、RegistrationId FROM SELECT*、Random AS randomRegistrationId FROM userInformation order by randomRegistrationId LIMIT.$GroupSize。作为jI get{query failed Undeclared variable:groupInformation}尝试将此插入到groupInformation中,从SELECT*中选择RegistrationId,从userInformation order by RAND LIMIT.$GroupSize。作为jIf,如果您只需要单列,请尝试将此插入groupInformationRegistrationId从SELECT*中选择RegistrationId从userInformation按兰德限制排序。$GroupSize。作为jSorry,您的两个屏幕截图属于同一个表。很抱歉,请尝试将此插入到groupInformationGroupId、RegistrationId选择randomRegistrationId、RegistrationId FROM SELECT*、Random AS randomRegistrationId FROM userInformation order by randomRegistrationId LIMIT.$GroupSize。当jI得到零作为RandomGroupId时,我得到零作为RandomGroupId。