Hi,

I have four inputs.

10 20

and 10 "NA"

i want to show that
10+"NA" > 10+20

How to do this??

Recommended Answers

All 6 Replies

Well to add the 10 and NA you will need to convert NA to an integre/number. So the following should do the job:

$var1=str_replace('NA',0,$_GET['input1']);
$var2=str_replace('NA',0,$_GET['input2']);
$var3=str_replace('NA',0,$_GET['input3']);
$var4=str_replace('NA',0,$_GET['input4']);
if (($var1+$var2)>($var3+$var4)) {
//blah
}

However you may want to replace $_GET with whatever you already have in place.

echo $var1=10+"NA";
   echo"<br>".$var2=10+20;

Output :-
10
30

And i want to show that
10+"NA" > 10+20

I tested the if statement you've suggested and no error occured so I don't see what the problem is. Below is an example of my script.

<?
if (10+"NA" > 10+20) {
echo 'passed if';
} else {
echo 'failed if';
}
?>

Hi, cwarn23

Out put out your program is :- failed if

I want here output :- passed if

I give the explanation what i want
10 + "Na"= 10 and 10 +20=30
But NA means not applicable we can't consider as value
so we use as 10+20 i.e 30 in processing.

So i want to show (10+"NA") > (10+20)
How to do this????

If you just want the opposite result then the following should do the job.

<?
if (10+"NA" < 10+20) {
echo 'passed if';
} else {
echo 'failed if';
}
?>

So i want to show (10+"NA") > (10+20)
How to do this????

<?
$na="N/A";
$val=$na;
$val1=10;
$val3=10;$val4=10;
if($val=="$na") {
if($val1>($val3+$val4)) [B]echo "$val1+N/A &gt; $val3+ $val4";
else echo "$val1+N/A &lt; $val3+ $val4";[/B]}
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.