This topic is locked

display and edit in TIME-format, when field is in INT

8/8/2011 8:19:13 AM
PHPRunner General questions
T
telematics author

hi,
please can you show me how i can view AND edit a field as TIME (hh:mm:ss) when it will be stored as integer (seconds)?
for VIEW calculating from seconds to time works perfect with following code:

$temp = $value;

$std = floor($temp/3600);

$rest = $temp%3600;

$min = floor($rest/60);

$sec = $rest%60;

if($std<10) { $std = "0".$std;}

if($min<10) { $min = "0".$min;}

if($sec<10) { $sec = "0".$sec;}

$value= $std.":".$min.":".$sec



but when i click to edit, I get the value in seconds again.
changing the database field to time is no option.
regards

HW

C
cgphp 8/8/2011

Place the code also in the "Process record values" event of edit pages.

$temp = $values['your_int_field_name'];

$std = floor($temp/3600);

$rest = $temp%3600;

$min = floor($rest/60);

$sec = $rest%60;

if($std<10) { $std = "0".$std;}

if($min<10) { $min = "0".$min;}

if($sec<10) { $sec = "0".$sec;}

$values['your_int_field_name']= $std.":".$min.":".$sec;
T
telematics author 8/8/2011

hi,
your solution above works fine, thank you. the only problem is now, that the field always shows 00:00:00 after saving. only when i reload the page, the values are displayed correct. any comments how to show the correct field content immediately after save?
regards,

HW

C
cgphp 8/8/2011

In the "Before record updated" and in the "Before record added":

$time_arr = explode(":", $values['your_int_field_name']);

$values['your_int_field_name'] = ($time_arr[0] * 3600) + ($time_arr[1] * 60) + $time_arr[2];
T
telematics author 8/8/2011

hi again,
i entered your given codes in both events. the effect is different: after adding a new record, the field is diplayed correctly, after inline-editing an existing record, the field is first 00:00:00 and after reloading it contains the correct time value.
is there a different refresh procedure between adding and editing when displaying the new/changed records?
regards,

HW

T
telematics author 8/8/2011

i just found out, that after "inline-edit", the field which was edited in (hh:mm:ss)-format will be interpreted as integer (seconds) and will be cutted at the first colon. e.g., when i enter 12:34:56, then after save it displays: 00:00:12. only after reload, it shows correctly 12:34:56.
which event(?) can be used for displaying the correct value immediately after saving an inline-edited record with field changes during events?
regards,

HW

C
cgphp 8/8/2011

As workaround, place this code in the Javascript Onload event of the add and edit pages:

this.on('afterSave', function(formObj, fieldControlsArr, pageObj){

location.href = "yourpagename_list.php";

});
T
telematics author 8/9/2011

sorry,
also with this workaround it has the same behaviour. the new value is not displayed until the page will be reloaded.
regards,

HW

C
cgphp 8/9/2011

Are you sure you have inserted the correct name for your list page ? The above piece of code reload the page after a record is added or updated.

T
telematics author 8/9/2011

hmm, doesn´t work. javascript in my browser is on.
must the path be changed? the php files are under root.
but i also cannot find the piece of code in any generated file (FILENAME_list.php, FILENAME_edit.php, FILENAME_add.php, jsfunctions.js). where it should be?
regards,

HW

C
cgphp 8/9/2011

Does firebug throw some errors ?

T
telematics author 8/10/2011

no errors or warnings in firebug. debugging the page shows all steps, but no reload.
in the meantime i found the pieces of code in "include/runnerJS/events/pageevents_FILENAME.js". it looks correctly.
regards,

HW

Sergey Kornilov admin 8/10/2011

If you need more help with troubleshooting post your application to Demo Account and open a ticket at http://support.xlinesoft.com sending your Demo Account URL. 'Demo Account' button can be found on the last screen in the program.