close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

change date format on multiple update

Thread began 8/19/2011 1:54 am by georgina_barrett_187762 | Last modified 9/08/2011 6:36 am by Jason Byrnes | 2127 views | 5 replies |

georgina_barrett_187762

change date format on multiple update

I need to display dates in 'd F Y' format and this is the format that users will input dates into the database. When inserting them in a single insert/update I use:

".((!empty($_POST["DateAdded"]))?date("Y-m-d", strtotime($_POST["DateAdded"])):"") ."

to convert the date back into the format for the database to store it.

The problem is with multiple inserts/updates I can display it in the correct format but how do I upload the date and change it to Y-m-d?

This is my code:

<?php
// WA DataAssist Multiple Updates
if (isset($_POST["Update_x"])) // Trigger
{
if (!session_id()) session_start();
$WA_loopedIDField = array("WADA_RepeatID_ConversationID");
$WA_connection = $flybuy;
$WA_table = "Conversation";
$WA_redirectURL = "";
$WA_keepQueryString = false;
$WA_indexField = "ConversationID";
$WA_fieldNamesStr = "DateAdded|Type|Type2|HandledBy|ConText|Action";
$WA_columnTypesStr = "',none,NULL|',none,''|',none,''|',none,''|',none,''|',none,''";
$WA_fieldNames = explode("|", $WA_fieldNamesStr);
$WA_columns = explode("|", $WA_columnTypesStr);
$WA_connectionDB = $database_flybuy;
$WA_multipleUpdateCounter = 0;
mysql_select_db($WA_connectionDB, $WA_connection);
while (WA_AB_checkLoopedFieldsNotBlank($WA_loopedIDField, $WA_multipleUpdateCounter)) {
$WA_fieldValuesStr = "".WA_AB_getLoopedFieldValue("DateAdded2", $WA_multipleUpdateCounter) ."" . "|" . "".WA_AB_getLoopedFieldValue("Type", $WA_multipleUpdateCounter) ."" . "|" . "".WA_AB_getLoopedFieldValue("Type2", $WA_multipleUpdateCounter) ."" . "|" . "".WA_AB_getLoopedFieldValue("HandledBy", $WA_multipleUpdateCounter) ."" . "|" . "".WA_AB_getLoopedFieldValue("ConText", $WA_multipleUpdateCounter) ."" . "|" . "".WA_AB_getLoopedFieldValue("Action", $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());
$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);
}
}
?>

Sign in to reply to this post

Jason ByrnesWebAssist

please compress the php page to a zip archive so i can see the entire page code in context.

Sign in to reply to this post

georgina_barrett_187762

Thank you. Zip file is attached. I have changed the format from 'd F Y' to 'd M Y'.

Attached Files
Complaint_Update.zip
Sign in to reply to this post

Jason ByrnesWebAssist

ok, all of the date form elements in the repeated region are named "DateAdded2_<int>" where <int> is an incrementing integer.

we can use the substr() method to look at the elements name, and if the first 11 characters of the name are "DateAdded2_", use the date function to convert the date format

add the following code at line 1 to accomplish this:

php:
<?php

if($_SERVER['REQUEST_METHOD'] == "POST") {
    foreach(
$_POST as $k => $v) {
        if(
substr($k011) == "DateAdded2_"$_POST[$k] = date("Y-m-d h:m:s"strtotime($_POST[$k]));
        
    }
}
?>
Sign in to reply to this post

georgina_barrett_187762

Thank you very much - I don't fully understand the working - but it works like a dream. Thanks again

Sign in to reply to this post

Jason ByrnesWebAssist

OK I'll give a brief explanation of each line, to hopefully make it a bit clearer.


the first line is an if statement that causes the code to only execute if there is a form post:

php:
if($_SERVER['REQUEST_METHOD'] == "POST") {



the next line creates a loop using the foreach() construct that goes through each form element, it breaks the form element name into a variable named $k and the element value into a variable named $v:

php:
foreach($_POST as $k => $v) {



the next line is really 2 lines, the first part looks at the element name which is stored in the $k variable, it takes the first 11 characters of the element name to see if it is equal to "DateAdded2_" using the substr() function:

php:
if(substr($k, 0, 11) == "DateAdded2_")



if it is equal to "DateAdded2_", it performs the date format to reformat the using the Y-m-d h:m:s format that is expected by the MySQL database

php:
$_POST[$k] = date("Y-m-d h:m:s", strtotime($_POST[$k]));
Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...