|
-
May 11th, 2012, 02:38 PM
#1
If row contains certain value then = a number
I am a total newbie at php. I have a script I am working with and need to change the way something works.
Basically I need this script to look at the value of a certain column in a row and depending on what it is turn it into a number value.
The column I am working with is called 'shippingsvc'. It will have one of these four values in it:
Standard Shipping
Local Pickup
Free Shipping
Economy Shipping
So if the value is "Standard Shipping" I would like it to bring back '125'.
If it is "Local Pickup" = '126'
If it is "Free" = '127'
If it is "Economy Shipping" = '128'
I know this code below will probably not work but it might give you an idea of what I am looking to do.
Code:
if($row['shippingsvc']="Standard Shipping" {$shippingservice='125';}
if($row['shippingsvc']="Local Pickup" {$shippingservice='126';}
if($row['shippingsvc']="Free Shipping" {$shippingservice='127';}
if($row['shippingsvc']="Economy Shipping" {$shippingservice='128';}
I would appreciate any help.
-
May 12th, 2012, 04:43 PM
#2
Re: If row contains certain value then = a number
Very close. 3 changes...
- When assigning value, you use =. When checking you may use a bunch of others. In your case, you want ==.
- You're forgetting the closing parenthesis.
- PHP is a loose typed language. Don't close the 125-128 in single quotes.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
May 15th, 2012, 08:22 AM
#3
Re: If row contains certain value then = a number
I think you should query the matrix entry, saving the resultant string, and then testing that using a switch. I'm new to PHP myself though, so I'm just thinking out loud here. But it i think accessing array entries multiple times is slower than accessing once and saving the result.
-
May 15th, 2012, 10:30 AM
#4
Re: If row contains certain value then = a number
gakushya, I don't even know what you're talking about.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|