如何在我的消息表中为 users.MM_Division = Division.divisionid 的每个 user.ID 插入表条目
我想在 messages.messagesuserid 中插入用户 ID 值
我想我需要一个while循环,但我不确定在处理插入查询时如何实现它。
目前,只有 1 条消息行被插入到消息表中的消息用户 ID 值帖子为 NULL
谢谢
这是我的代码:
session_start();
$colname_division = "-1";
if ((isset($_GET['divisionid'])) && ($_GET['divisionid'] != "")) {
$colname_division = $_GET['divisionid'];
mysql_select_db($database_connect, $connect);
$query_users = sprintf("SELECT users.*, division.* FROM users INNER JOIN division ON division.divisionid = users.MM_Division WHERE divisionid = %s", GetSQLValueString($colname_users, "int"));
$users = mysql_query($query_users, $connect) or die(mysql_error());
$row_users = mysql_fetch_assoc($users);
$totalRows_users = mysql_num_rows($users);
// MESSAGE USERS DIVISION ARCHIVED
$messageinsertSQL = sprintf("INSERT INTO messages (message, messageuserid) VALUES ('The division " . $row_division['division'] . " has been archived by " . $_SESSION['MM_Username'] . " please select a new division', '" . $row_users['ID'] . "')",GetSQLValueString($_GET['divisionid'], "int"));
mysql_select_db($database_connect, $connect);
$Result4 = mysql_query($messageinsertSQL, $connect) or die(mysql_error());
// REDIRECT
$updateGoTo = "../divisions.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
mysql_free_result($division);
exit;
}