If...else expression

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
petek
Forum Newbie
Posts: 3
Joined: Wed Apr 02, 2008 3:20 pm

If...else expression

Post 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
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: If...else expression

Post 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 &&
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
petek
Forum Newbie
Posts: 3
Joined: Wed Apr 02, 2008 3:20 pm

Re: If...else expression

Post 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
petek
Forum Newbie
Posts: 3
Joined: Wed Apr 02, 2008 3:20 pm

Re: If...else expression

Post 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
Post Reply