DataAssist Multiple Update
I would like a skip if empty option as per the Insert Multiple Records behaviour so that only the modified records are changed. See index.php?action=update-multiple as an example of what I mean. I am using some JS to check for changes in the text boxes / radio buttons and checking the update box.
The modified update code looks like:
// WA DataAssist Multiple Updates (Modified to do update check)
if (isset($_POST["updateMultiple"])) // Trigger
{
if (!session_id()) session_start();
$WA_loopedIDField = array("WADA_RepeatID_id");
$WA_connection = $connDB;
$WA_table = "tbl_pages";
$WA_redirectURL = "../../pages/index.php?update-multiple=true";
if (function_exists("rel2abs")) $WA_redirectURL = $WA_redirectURL?rel2abs($WA_redirectURL,dirname(__FILE__)):"";
$WA_keepQueryString = true;
$WA_indexField = "id";
$WA_fieldNamesStr = "title|slug|publish|tstampupdate|url|dateupdate|adminupdate|showmenu";
$WA_columnTypesStr = "',none,''|',none,''|none,none,NULL|none,none,NULL|',none,''|',none,NULL|none,none,NULL|none,none,NULL";
$WA_insertIfNotBlank = "updateCheck"; // define checkbox name
$WA_fieldNames = explode("|", $WA_fieldNamesStr);
$WA_columns = explode("|", $WA_columnTypesStr);
$WA_connectionDB = $database_connDB;
$WA_multipleUpdateCounter = 0;
mysql_select_db($WA_connectionDB, $WA_connection);
while (WA_AB_checkLoopedFieldsNotBlank($WA_loopedIDField, $WA_multipleUpdateCounter)) {
if ($WA_insertIfNotBlank == "" || WA_AB_checkLoopedFieldsNotBlank(array($WA_insertIfNotBlank), $WA_multipleUpdateCounter)) { // start check loop
$WA_fieldValuesStr = "".WA_AB_getLoopedFieldValue("title", $WA_multipleUpdateCounter) ."" . "|" . "".i8_UrlParameter(WA_AB_getLoopedFieldValue("slug", $WA_multipleUpdateCounter)) ."" . "|" . "".WA_AB_getLoopedFieldValue("publish", $WA_multipleUpdateCounter) ."" . "|" . "".WA_AB_getLoopedFieldValue("tstampupdate", $WA_multipleUpdateCounter) ."" . "|" . "".i8_UrlParameter(WA_AB_getLoopedFieldValue("title", $WA_multipleUpdateCounter)) ."" . "|" . "".WA_AB_getLoopedFieldValue("dateupdate", $WA_multipleUpdateCounter) ."" . "|" . "".WA_AB_getLoopedFieldValue("adminupdate", $WA_multipleUpdateCounter) ."" . "|" . "".WA_AB_getLoopedFieldValue("showmenu", $WA_multipleUpdateCounter) ."";
$WA_fieldValues = explode("|", $WA_fieldValuesStr);
$WA_where_fieldValuesStr = WA_AB_getLoopedFieldValue($WA_loopedIDField[0], $WA_multipleUpdateCounter);
$WA_where_columnTypesStr = "none,none,NULL";
$WA_where_comparisonStr = "=";
$WA_where_fieldNames = explode("|", $WA_indexField);
$WA_where_fieldValues = explode("|", $WA_where_fieldValuesStr);
$WA_where_columns = explode("|", $WA_where_columnTypesStr);
$WA_where_comparisons = explode("|", $WA_where_comparisonStr);
$updateParamsObj = WA_AB_generateInsertParams($WA_fieldNames, $WA_columns, $WA_fieldValues, -1);
$WhereObj = WA_AB_generateWhereClause($WA_where_fieldNames, $WA_where_columns, $WA_where_fieldValues, $WA_where_comparisons );
$WA_Sql = "UPDATE `" . $WA_table . "` SET " . $updateParamsObj->WA_setValues . " WHERE " . $WhereObj->sqlWhereClause . "";
$MM_editCmd = mysql_query($WA_Sql, $WA_connection) or die(mysql_error());
} // end check loop
$WA_multipleUpdateCounter++;
}
if ($WA_redirectURL != "") {
if ($WA_keepQueryString && $WA_redirectURL != "" && isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] !== "" && sizeof($_POST) > 0) {
$WA_redirectURL .= ((strpos($WA_redirectURL, '?') === false)?"?":"&").$_SERVER["QUERY_STRING"];
}
header("Location: ".$WA_redirectURL);
}
}