CalcBuilder Forum

if else fuction

Usuario todanai 2015-02-05 10:00:14

Dear all, I have the fuction. If epan>2 then I want to see the results in the result layout else I want to have an error message asking user to insert new values. Unfortunately I don't know what to put after "else"

This is the half of the code:

$aferesi=$mashali-$omos;
$afer=$aferesi/2;
$epal=sires/afer;
if ($epal > "2") {
$p=$sires-$aferesi;
$p2=$p/2;
$x=$afer-$p2;
}
else {
I want to see a message error or a pop up error!!!??
}

Moonsoft support 2015-02-05 11:18:51

Hi,
if you were printing a single result, like $result, you could use that approach to set $result with the if/else structure:

if($epal>2){
//calculations
$result=376;
}

else{

$result="Error:Message";
}


but looking at your code, seems you are calculating several results, so we'd use this solution instead:


At your exit layout, create the two sections (real results, and error message). Enclose each one inside a div and set a different style for each one:

//real results

...div style="display:##displayreal##"


//here your result section..close div


//error section

..div style="display:##displayerror##"

//here your error section...close div



and now you can set at the code the display of each section according to your condition:


//calculations

if($epal>2){

$displayreal="block";
$displayerror="none";
}

else{
$displayreal="none";
$displayerror="block";

}


Please let us know if you need further help with this.


Thanks, regards

...
List Manager

Build different lists for your site

Buy now!
...
CalcBuilder

Create dynamic calculators

Buy now!