943,678 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 877
  • PHP RSS
Jun 27th, 2009
0

String and integer value comparision??

Expand Post »
Hi,

I have four inputs.

10 20

and 10 "NA"

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

How to do this??
Similar Threads
Reputation Points: 3
Solved Threads: 15
Posting Whiz
Aamit is offline Offline
341 posts
since Apr 2008
Jun 27th, 2009
0

Re: String and integer value comparision??

Well to add the 10 and NA you will need to convert NA to an integre/number. So the following should do the job:
php Syntax (Toggle Plain Text)
  1. $var1=str_replace('NA',0,$_GET['input1']);
  2. $var2=str_replace('NA',0,$_GET['input2']);
  3. $var3=str_replace('NA',0,$_GET['input3']);
  4. $var4=str_replace('NA',0,$_GET['input4']);
  5. if (($var1+$var2)>($var3+$var4)) {
  6. //blah
  7. }
However you may want to replace $_GET with whatever you already have in place.
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,004 posts
since Sep 2007
Jun 27th, 2009
0

Re: String and integer value comparision??

PHP Syntax (Toggle Plain Text)
  1. echo $var1=10+"NA";
  2. echo"<br>".$var2=10+20;

Output :-
10
30

And i want to show that
10+"NA" > 10+20
Reputation Points: 3
Solved Threads: 15
Posting Whiz
Aamit is offline Offline
341 posts
since Apr 2008
Jun 28th, 2009
0

Re: String and integer value comparision??

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.
php Syntax (Toggle Plain Text)
  1. <?
  2. if (10+"NA" > 10+20) {
  3. echo 'passed if';
  4. } else {
  5. echo 'failed if';
  6. }
  7. ?>
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,004 posts
since Sep 2007
Jun 28th, 2009
0

Re: String and integer value comparision??

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????
Reputation Points: 3
Solved Threads: 15
Posting Whiz
Aamit is offline Offline
341 posts
since Apr 2008
Jun 28th, 2009
0

Re: String and integer value comparision??

If you just want the opposite result then the following should do the job.
php Syntax (Toggle Plain Text)
  1. <?
  2. if (10+"NA" < 10+20) {
  3. echo 'passed if';
  4. } else {
  5. echo 'failed if';
  6. }
  7. ?>
Sponsor
Featured Poster
Reputation Points: 410
Solved Threads: 258
Occupation: Genius
cwarn23 is offline Offline
3,004 posts
since Sep 2007
Jun 28th, 2009
0

Re: String and integer value comparision??

Click to Expand / Collapse  Quote originally posted by Aamit ...
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)) echo "$val1+N/A &gt; $val3+ $val4";
else echo "$val1+N/A &lt; $val3+ $val4";}
?>
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
m-soft is offline Offline
52 posts
since Oct 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: My database connection dies but doesnt print an error
Next Thread in PHP Forum Timeline: SESSION LIFE( TIME) problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC