If Condition in Field Expression

how to use if condition in expression field in phprad
example :
if a > b then
result = ab
else
result ba

Doing that will be a little hard for older versions of Classic as it is a partial SQL query, which means it is part of the main page query.

If you are using the latest Radsystems Studio, the below example should help when you switch from Custom SQL Field to Template Field on Radsystems Studio Classic.

@if(item.fieldname > item.fieldname2)
<div>{{ item.fieldname  }} {{ item.fieldname2  }}</div>
@else
<div>{{ item.fieldname2  }} {{ item.fieldname  }}</div>
@endif

hi willvin, thanks for the kind response,
I have tried the code you suggested but it doesn’t work on classic phprad.
is there any suggestion and solution for this problem?

What version of classic are you using?

Php rad classic v 2.7.3

Use the PHPRad Classic 2.7.3 Forum for related questions, the above solution was for Radsystems Studio. As I said, it will be difficult to get it done on the old classic versions.

thankyou for the response,
I am also a user of radsystem version 8.1.6.
I also followed the example of the code snippet that you provided above on radsystem but it also didn’t run smoothly.


The image you posted shows that you didn’t follow the instructions. You applied the code I gave you for Template Field to Custom SQL Field. Look at the interface and switch to Template Field to apply the code.

Hi Willvin,
I have selected the template field and an error like this appears


I don’t know if you are working on a view page or list page, look at the code example at the top of the panel and adjust the below code accordingly to suit it.

@if($data['fieldname' > $data['fieldname2'])
<div><?php echo (float)$data['fieldname'] + (float)$data['fieldname2']; ?></div>
@else
<div><?php echo (float)$data['fieldname'] - (float)$data['fieldname2']; ?></div>
@endif

Access to variables changes from version to version in Radsystems Studio. The initial code works for the latest version of Radsystems Studio.