This topic is locked
[SOLVED]

 Help understanding functions in PHPRunner

11/4/2011 7:49:21 PM
PHPRunner General questions
W
wildwally author

Ok, I've got a firm grasp on the basis of using queries and getting things to do what i want for the most part - but this last issue has me racking my brain over and over. I think my VBA programing train of thought is blending into the picture which might have things not working like it should.
When using custom functions in PHPRunner where would one put it? I'm assuming the event sections, correct?
What I have is the weekday code found Here, I'm trying to get the section of code on my "Before record updated" to call the function and return the value.
On my "Before record updated"


$values['workingDays'] = getWorkingDays1($startDate,$endDate,$holidays);

echo "(--> ".$values['workingDays']." <--)";


And I've added a PHP snippet renamed getWorkingDays1 in the Edit Page. See the link to see the code contained within the snippet.
I'm getting a Undefined variable: values error on the page.
I tried have the code on the same page but the return closes out the event and the rest of my if is not executed. So can someone explain where I'm going wrong? In VBA(Excel) I can store a procedure in the modules and call upon it throughout - is that possible here?

W
wildwally author 11/4/2011



Check this article: http://xlinesoft.com...ernal_files.htm


I'm not seeing anything that relates or shows an example.
If the function getworkingdays requires values from the event code how does one pass the value? Do i need to create a session variable to do this?

C
cgphp 11/4/2011

$values is the array to access fields values of the add/edit pages.
Is workingDays the real name of a field of the table in the database ?
Don't add the getWorkingDays1 function in a PHP snippet. Add it directly into the "Before record update" event or (better) in the "After application initialized" event as you can read in the above link.

W
wildwally author 11/4/2011



$values is the array to access fields values of the add/edit pages.
Is workingDays the real name of a field of the table in the database ?
Don't add the getWorkingDays1 function in a PHP snippet. Add it directly into the "Before record update" event or (better) in the "After application initialized" event as you can read in the above link.


Trying the second suggestion right now.
I am adding this value to the db and I want to echo, yes a real name. And I have the $startdate and $Enddate as fields that have my user entered data and I want the function to use that data then return me the value after calculations.
So if I understand this at the start of the event I'm going to include:

include("workdays.php");


Which is the name of the file that contains my function. And in the even I'll call that function with:

$values['workingDays'] = getWorkingDays($values,$startDate,$endDate,$holidays);
W
wildwally author 11/4/2011

Thanks for your guidance - got it working.

C
cgphp 11/4/2011

Add the include statement to the "After table initialized" event (as explained in the above link). Call the getWorkingDays function with:

$values['workingDays'] = getWorkingDays($values['startDate'],$values['endDate'],$values['holidays']);