This topic is locked

Checkbox event to change field values

12/30/2021 3:48:18 AM
PHPRunner General questions
D
Dynamiccomp author

I have a couple checkboxes which I have, that if they are checked, I need to beable to change a few of the fields, these fields have mysql queries, and some simple math calculations in the before record updated event.

I've been playing around with the code in the event record and this is what i have been experimenting with:

if ($values['Eliminated'] = ('on')) {
$values['Final Total'] = 0;
}
else
{}

I have also tried this code to include all 3 checkboxes in a single command

if ($values['Eliminated'] || $values['Withdrew'] || $values['Scratched'] == 'on')) {
$values['Final Total'] = 0;
$values['Final Rank'] = null;
}
else
{
}

I also was looking to see if it might be better to use the field event "on click" but i'm not exactly sure what i need to put in each of the 3 sections.

Could someone please give me some guidance on where to start, I would greatly appreciate it, since I am a bit out of my league right now?

Admin 12/30/2021

I see you are struggling with the basic IF syntax. Here are a couple of examples:

Single condition:
if ($values['Eliminated'] == 'on') { ... }

Note the use of == instead of = . This is extremely important.

Multiple conditions:
if ($values['Eliminated'] == 'on' || $values['Withdrew'] == 'on' ) { ... }

D
Dynamiccomp author 12/30/2021

Thank you for you help with that, as I didn't realize I had made that mistake.

It works, however if I have a calculation in the events page, or a SQL query for that field, the if statement doesn't get applied. Do you know how I can solve this issue?

For example my if statement:

if ($values['Eliminated'] == 'on' || $values['Scratched'] == 'on' || $values['Withdrew'] == 'on') {
$values['Final Rank'] = "E";
}
else
if ($values['Eliminated'] == 'off' || $values['Scratched'] == 'off' || $values['Withdrew'] == 'off') {
}

In my before record update event page I have:

$values['Final Rank'] = $values['Total'] / $values['competitors'];

or if i put the following in the SQL query:

FIND_IN_SET(`Final Total`, (
SELECT GROUP_CONCAT( DISTINCT `Final Total`
ORDER BY `Final Total` ASC ) FROM Scoring)) AS `Final Rank`,

my If statement above doesn't get applied. is there a way to override the calculation or the SQL query with my if statement?