Page 1 of 1

If...else expression

Posted: Wed Apr 02, 2008 3:24 pm
by petek
Hi,

I have the following expression only the first part of which is being taken into account, ie whether the result is true or false, only the true is being printed

Code: Select all

$sips = $this->makeRequest($order->info['total'], $currency);
      
       if ($sips = $this->makeRequest($order->info['total'], $currency) > 200)  { 
     echo $sips = $this->makeRequest($order->info['total']*0.30, $currency);
} else {
    echo $sips = $this->makeRequest($order->info['total'], $currency);
}
echo '">'."\n";
What am I doing wrong ?

Cheers

Pete

Re: If...else expression

Posted: Wed Apr 02, 2008 3:30 pm
by s.dot

Code: Select all

if ($sips = $this->makeRequest($order->info['total'], $currency) > 200)  {
:arrow:

Code: Select all

if ($sips > 200)  {
If you wanted to use the expression that you are using, you'd have to make two comparisons and use &&

Re: If...else expression

Posted: Thu Apr 03, 2008 1:32 am
by petek
Thanks for you reply but sorry, PHP is rocket science for me ! Should the code be :

Code: Select all

  $sips = $this->makeRequest($order->info['total'], $currency);
if ($sips > 200)  {
echo $sips = $this->makeRequest($order->info['total']*0.30, $currency);
} else {
 echo $sips = $this->makeRequest($order->info['total'], $currency);
}
echo '">'."\n";


or rather :

Code: Select all

$sips = $this->makeRequest($order->info['total'], $currency);
if ($sips > 200)  {
echo ($sips *0.30); [b]with or without the brackets ?[/b]
} else {
 echo $sips;
}
echo '">'."\n";
If not, how do I use "&&" when there's only one variable ?

Thanks

Pete

Re: If...else expression

Posted: Fri Apr 04, 2008 5:20 am
by petek
Well, this what I have so far :

Code: Select all

if ($sips > 200)  {
      echo $sips = $this->makeRequest($order->info['total']*0.30, $currency);
      } else {
      echo $sips = $this->makeRequest($order->info['total'], $currency);
      }
      echo '">'."\n";
I don't where to put the comparison and &&. Any ideas ?

Cheers

Pete