我需要帮助将我的查询结果插入到另一个表中,并为每个结果提供一个id号 .
$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 group Id must increment by every group created
//$query ="Select RegistrationId from userInformation order by RAND() LIMIT ".$GroupSize;
$query = "INSERT INTO groupInformation SELECT RegistrationId FROM (SELECT RegistrationId FROM userInformation ORDER BY RAND() LIMIT ".$GroupSize.")";
$result = mysqli_query($con, $query) or die ("query failed " . mysqli_error($con));
while (($row = mysqli_fetch_row($result)) == true) {
echo $row[0].'
';
}
我的表userInformation在RegistrationId上有一个主键,在groupInformation中有RegistrationId上的外键 . groupInformation中的Group Id将逐步自动生成每个结果的ID .
我知道我需要使用while循环或foreach,但我不知道如何 .