CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2012
    Posts
    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.

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    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.

  3. #3
    Join Date
    Jan 2012
    Location
    toronto
    Posts
    13

    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.

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    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
  •  





Click Here to Expand Forum to Full Width

Featured