String and integer value comparision??

Reply

Join Date: Apr 2008
Posts: 296
Reputation: Aamit has a little shameless behaviour in the past 
Solved Threads: 11
Aamit Aamit is offline Offline
Posting Whiz in Training

String and integer value comparision??

 
0
  #1
Jun 27th, 2009
Hi,

I have four inputs.

10 20

and 10 "NA"

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

How to do this??
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,544
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 137
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Posting Virtuoso

Re: String and integer value comparision??

 
0
  #2
Jun 27th, 2009
Well to add the 10 and NA you will need to convert NA to an integre/number. So the following should do the job:
  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.
Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*`
My favourite PC. - Oopy Doopy Do 2U2!
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 296
Reputation: Aamit has a little shameless behaviour in the past 
Solved Threads: 11
Aamit Aamit is offline Offline
Posting Whiz in Training

Re: String and integer value comparision??

 
0
  #3
Jun 27th, 2009
  1. echo $var1=10+"NA";
  2. echo"<br>".$var2=10+20;

Output :-
10
30

And i want to show that
10+"NA" > 10+20
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,544
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 137
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Posting Virtuoso

Re: String and integer value comparision??

 
0
  #4
Jun 28th, 2009
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.
  1. <?
  2. if (10+"NA" > 10+20) {
  3. echo 'passed if';
  4. } else {
  5. echo 'failed if';
  6. }
  7. ?>
Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*`
My favourite PC. - Oopy Doopy Do 2U2!
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 296
Reputation: Aamit has a little shameless behaviour in the past 
Solved Threads: 11
Aamit Aamit is offline Offline
Posting Whiz in Training

Re: String and integer value comparision??

 
0
  #5
Jun 28th, 2009
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????
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,544
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 137
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Posting Virtuoso

Re: String and integer value comparision??

 
0
  #6
Jun 28th, 2009
If you just want the opposite result then the following should do the job.
  1. <?
  2. if (10+"NA" < 10+20) {
  3. echo 'passed if';
  4. } else {
  5. echo 'failed if';
  6. }
  7. ?>
Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*`
My favourite PC. - Oopy Doopy Do 2U2!
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 52
Reputation: m-soft is an unknown quantity at this point 
Solved Threads: 0
m-soft m-soft is offline Offline
Junior Poster in Training

Re: String and integer value comparision??

 
0
  #7
Jun 28th, 2009
Originally Posted by Aamit View Post
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";}
?>
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 551 | Replies: 6
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC