Quote:
Originally Posted by AndrewGSW
Well you could cheat - side-step the parameters on this occasion only! As long as you ensure that the message-ids are ALL INTEGER NUMBERS you could embed them into the sql-statement.
The 'W' on the third line is to ensure that all characters are numbers. If a value of 12.34 is obtained, it is converted to '12W34' and it will no longer pass the is_numeric() test.
PHP Code:
if (isset($messagesToUpdate) && $messagesToUpdate) {
// Update Selected Messages.
if (!is_numeric(str_replace('.', 'W', implode('', $messagesToUpdate))) {
// at least one of them isn't an integer: bail!
}
$parmcount = count($messagesToUpdate);
$inclause = implode(',', $messagesToUpdate);
// Build query.
$q1 = "UPDATE private_msg_recipient
SET read_on = NULL,
updated_on = NOW()
WHERE member_id_to = ?
AND message_id IN (%s)";
$preparesql = sprintf($q1, $inclause);
// Prepare statement.
$stmt1 = mysqli_prepare($dbc, $preparesql);
// Bind variable to query.
mysqli_stmt_bind_param($stmt1, 'i', $sessMemberID);
// Execute query.
mysqli_stmt_execute($stmt1);
// Verify Update.
if (mysqli_stmt_affected_rows($stmt1) == 1) {
// Update Succeeded.
} else {
// Update Failed.
}
|
Wow! That is a radical, yet innovative, approach?!
Honestly, though, while I waited for your response I started re-working my original code using a loop.
Here is what I came up with which isn't so bad, as it eliminates the duplicate code I originally wanted to avoid...
First I determine which Messages were selected...
PHP Code:
// ********************************
// Check for Messages Selected. *
// ********************************
if (empty($error)){
// Continue processing...
if (!empty($_POST['selectAll']) && $_POST['selectAll'] == 1){
// All Messages Selected.
$updateMsgArray = $_POST['msgArray'];
}elseif (!empty($_POST['selectedMsgArray']) && $_POST['selectedMsgArray']){
// Some Messages Selected.
$updateMsgArray = $_POST['selectedMsgArray'];
}else{
// No Messages Selected.
$error = 'Please choose a Message(s) to update.';
}
And as you can see, I just re-name/re-assign whichever $_POST array applies to a generic
$updateMsgArray one.
Then in my loop, I just use this single array to loop through, thus eliminating the need for two nearly identical blocks of code for "Select All" and "Select Some" scenarios...
PHP Code:
foreach($updateMsgArray as $msgID => $msgValue){
// Build query.
$q1 = "UPDATE private_msg_recipient...
Now, from a Database Server standpoint, your approach is probably better, but since I am not GMail, I'm thinking this latest approach I came up with will suffice, although I am very impressed with your solution!!
What do you think?
Thanks,
Debbie