Hi,
I have a table with a field named "rank". I need this field set to 1, 2, 3, or 4 based on a selection made by a user in another field in the same table called "Risk". The "Risk" field is set as Radio buttons with the options, Low Risk, Medium Risk, High Risk and Stop Work. I've experimented with Calculated field for the field and have not gotten it yet.
Can anyone help?
Ray
Calculated Fields or Hooks?
Re: Calculated Fields or Hooks?
Ok, so I tried using the before_insert hook with if statements:
if($data['risk'] = "Low Risk"){$data['rank'] = 1;} and that worker fine if I only selected the "Low Risk" radio option. If I select any other radio option the selection changed to "Low Risk" when I save the record.
Then I added an additional if statement: if($data['risk'] = "Medium Risk"){$data['rank'] = 2;}. As long as I select radio option "Medium Risk" it works. If I select any other option it gets changed to "Medium Risk" when saved. The same issues exist if I use an elseif statement after the if statement.
if($data['risk'] = "Low Risk"){$data['rank'] = 1;} and that worker fine if I only selected the "Low Risk" radio option. If I select any other radio option the selection changed to "Low Risk" when I save the record.
Then I added an additional if statement: if($data['risk'] = "Medium Risk"){$data['rank'] = 2;}. As long as I select radio option "Medium Risk" it works. If I select any other option it gets changed to "Medium Risk" when saved. The same issues exist if I use an elseif statement after the if statement.
Re: Calculated Fields or Hooks?
Well, it seems to be working now. I found that using == rather than = for the condition statement made all the difference.
if($data['risk'] == "Low Risk"){$data['rank'] = 1;}
It helps just to ask this forum!! Even if I figure it out on my own.
if($data['risk'] == "Low Risk"){$data['rank'] = 1;}
It helps just to ask this forum!! Even if I figure it out on my own.
Re: Calculated Fields or Hooks?
In most programming languages '=' is a right-to-left assignment whereas '==' is a left against right comparison, returning boolean.
$a = 1;
$a = $a == 2;
// $a is false now
$a = 1;
$a = $a == 2;
// $a is false now
Kind regards,
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
AppGini 24.10 Revision 1579 + all AppGini Helper tools
<js />
My AppGini Blog:
https://appgini.bizzworxx.de/blog
You can help us helping you:
Please always put code fragments inside
[code]...[/code]
blocks for better readabilityAppGini 24.10 Revision 1579 + all AppGini Helper tools
Re: Calculated Fields or Hooks?
Thank you for that Jan!! I love getting helpful tidbits from you all.