How do I insert a table entry in my messages table for each user.ID where the users.MM_Division = division.divisionid
I want to insert the user ID value in the messages.messagesuserid
I think I need a while loop but I’m not sure how I implement it when dealing with a insert query.
Currently, only 1 message row is inserted into the messages table on the messageuserid value posts as NULL
Thanks
Here’s my code:
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;
}
Wrap that
message users division archivedpart with:Then you need to remove
$row_users = mysql_fetch_assoc($users)used earlier.BTW, I’m not sure if some columns won’t get overwritten if they have the same names (from users and divisions) in
$query_users =line.Besides, that line has wrong parameter
$colname_usersinGetSQLValueString()function (shouldn’t it be$colname_division? Or do you declare it somewhere else?).