473,486 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Conditional and Operator problem

2 New Member
Hello,
I'm new to PHP and need a liitle help with this code I'm working on.

Expand|Select|Wrap|Line Numbers
  1. $Shipping_Method = $METHOD;
  2. $dlr = 70.00;
  3.  
  4.     if ($Shipping_Method == 'Priority') 
  5.     {$Shipping_Method = 'Blue';}
  6.    else if ($Shipping_Method == 'Express Overnight') 
  7.     {$Shipping_Method = 'Red Saver';}
  8. else if ($TOTAL >= $dlr && $Shipping_Method == 'Ground'   ) 
  9.     {$Shipping_Method = 'Priority1';} 
  10.     else 
  11.     {$Shipping_Method = 'Ground';} 
  12.  
If the user chooses Priority shipping than the Shipping method will be Blue, ect. That part seems to work.
I stuck on is this part....
Expand|Select|Wrap|Line Numbers
  1. else if ($TOTAL >= $dlr && $Shipping_Method == 'Ground'   ) 
  2.     {$Shipping_Method = 'Priority1';} 
  3.     else 
  4.     {$Shipping_Method = 'Ground';} 
  5.  
If the total($TOTAL) is greater than 70($dlr) then the output should be "Priority1" if the total is less that 70 the output should be "Ground"

Every time I set the shipping method to ground and the total greater than 70 I get "Ground" where I should be getting "Priority"

What am I doing wrong?

Thanks in advance.
Jun 25 '08 #1
4 1975
Markus
6,050 Recognized Expert Expert
I can't seem to replicate your problem..

but something else I can add (thank god) is that when you use a conditional statement that only has one operation to execute, you need not use the curly braces.

EG:
Expand|Select|Wrap|Line Numbers
  1. # don't need braces
  2. if($i != $x)
  3.     echo "No braces";
  4.  
  5. # need braces
  6. if($i != $x)
  7. {
  8.     echo "Does need";
  9.     echo " braces";
  10. }
  11.  
Jun 25 '08 #2
Atli
5,058 Recognized Expert Expert
I can't seem to replicate the problem either.

What exactly is the value of $TOTAL?
Jun 26 '08 #3
Steve999
2 New Member
Hello,
My problem was $TOTAL was passing "$14.99", I removed the dollar sign so it was passing"14.99" and it works.

when you use a conditional statement that only has one operation to execute, you need not use the curly braces.
As for the curly braces I will removed those.

Thanks for your help
Jun 26 '08 #4
Markus
6,050 Recognized Expert Expert
Hello,
As for the curly braces I will removed those.

Thanks for your help
It's not necessary, but it just saves some keystrokes.

Regards.
Jun 26 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
4444
by: TheKeith | last post by:
I just wrote the following script for something I'm working on: ---------------------------------------------------------------------------- ------------------- <html> <head> <script...
26
1748
by: Ney André de Mello Zunino | last post by:
Hello. I have noticed, in a lot of C and C++ code, that many programmers seem to prefer putting the test values first in conditional expressions. I.e., they would rather write this: if (-1 ==...
6
3651
by: Mahesh Tomar | last post by:
Please see the code below :- void func() { unsigned char x,y,z=1; (z==1) ? (x) : (y) = 1; /* Compiles OK */ ((z==1) ? (x) : (y)) = 1; /* Compiler generates an error "Variable expected" */ }
4
4666
by: mux | last post by:
Hi I found out that the following piece of code throws an error. 1 #include "stdio.h" 2 3 int main() 4 { 5 int a,b; 6 a= 10;
6
12121
by: Chris Dunaway | last post by:
Consider this code (.Net 2.0) which uses a nullable type: private void button1_Click(object sender, System.EventArgs e) { DateTime? nullableDate; nullableDate = (condition) ? null :...
9
4755
by: Marty | last post by:
Hi, Does using the the conditional operator (?:) instead of the common "if" statement will give a performance gain in a C# .NET 2003 application (even in C# .NET 2005?). What is the advantage...
5
2886
by: paulo | last post by:
Can anyone please tell me how the C language interprets the following code: #include <stdio.h> int main(void) { int a = 1; int b = 10; int x = 3;
15
1773
by: Nicholas M. Makin | last post by:
I was just thinking that I understood the conditional operator when I coded the following expecting it to fail: int a= 10, b= 20, c= 0; ((a < b) ? a : b) = c; // a=0 a=20; b= 10; ((a < b) ? a...
3
2445
by: somenath | last post by:
Hi All, I have one question regarding the conditional operator. In the draft C99 standard it is mentioned that "1 The following are the sequence points described in 5.1.2.3: -- The call to a...
13
1538
by: Neal Becker | last post by:
In hindsight, I am disappointed with the choice of conditional syntax. I know it's too late to change. The problem is y = some thing or other if x else something_else When scanning this my...
0
7100
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7126
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6842
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7330
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4865
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4559
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3070
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
262
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.