Loop Insert from an array?
Hello,
I've searched the forums and not seen anything that points out how to take a current single record insert and then modify it IF there are more than one record to insert.
Any pointers on what it would take to modify the Insert behavior to do a loop inserting all values from an array?
Using the latest version of DA, in a PHP environment with MySQL 5.1
code:
// WA Application Builder Insert
if ($_SERVER["REQUEST_METHOD"] == "POST") // Trigger
{
$WA_connection = $emailList;
$WA_table = "phplist_user_user";
$WA_sessionName = "phplist_user_user_id";
$WA_redirectURL = "";
$WA_keepQueryString = false;
$WA_indexField = "id";
$WA_fieldNamesStr = "email|confirmed|uniqid|htmlemail|subscribepage";
$WA_fieldValuesStr = "".((isset($_POST["fldEmail"]))?$_POST["fldEmail"]:"") ."" . "|" . "1" . "|" . md5(uniqid(mt_rand())) . "|" . "1" . "|" . "4";
$WA_columnTypesStr = "',none,''|none,none,NULL|',none,''|none,none,NULL|none,none,NULL";
$WA_fieldNames = explode("|", $WA_fieldNamesStr);
$WA_fieldValues = explode("|", $WA_fieldValuesStr);
$WA_columns = explode("|", $WA_columnTypesStr);
$WA_connectionDB = $database_emailList;
mysql_select_db($WA_connectionDB, $WA_connection);
if (!session_id()) session_start();
$insertParamsObj = WA_AB_generateInsertParams($WA_fieldNames, $WA_columns, $WA_fieldValues, -1);
$WA_Sql = "INSERT INTO `" . $WA_table . "` (" . $insertParamsObj->WA_tableValues . ") VALUES (" . $insertParamsObj->WA_dbValues . ")";
$MM_editCmd = mysql_query($WA_Sql, $WA_connection) or die(mysql_error());
$_SESSION[$WA_sessionName] = mysql_insert_id();
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);
}
}
?>
Note, I'm also setting a random value to one of the fields and inserting php code as a value was not found as an option in the behavior dialog. No problem as I can remove the quotation marks making it no longer a string but it would be a nice enhancement to also use php functions as insert values.
I can also hand write the insert loop but the reason to use these extensions is the speed of implementation so learning how to loop an array in DA Insert would be of value.
Thanks,
Steve