Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2008
    Posts
    50
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Best Way To Do This

    I am trying to make a small script that gives an specific output given a certain combination of two input values. I am currently doing it with if, elseif and else statements which works fine up to a point, but I am wondering if there is a better and cleaner way to go about things.

    Basically, I want PHP to give a certain output depending on the country of the visitor and a number that they enter.

    For example, the script is a little like this...

    PHP Code:
                      if ($country == "country" && $money 50) {
                      
                      echo 
    'something';
                      
                      }
                      
                      elseif (
    $country == "country" && $money=> 50 && $money <= 50000// this will not work - too many &&s i think. {
                      
                      
    echo 'something else';
                      
                      } 
    The script goes on for a few more elseif statements, but I guess the biggest problem if giving an output if a person is from a certain country and the money value is BETWEEN two numbers.

    What would be the best solution?
    Last edited by Inersha; 08-15-2008 at 12:19 PM.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,858
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    PHP Code:
    if($country == "country" ){
       if(
    $money 50)
            echo 
    'something';
      elseif(
    $money>= 50 && $money <= 50000)
             echo 
    'something else';

    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    Inersha (08-15-2008)

  • #3
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Quote Originally Posted by abduraooft View Post
    PHP Code:
    if($country == "country" ){
       if(
    $money 50)
            echo 
    'something';
      elseif(
    $money>= 50 && $money <= 50000)
             echo 
    'something else';

    On my website the elseif start and closing has to be like this.

    Code:
    elseif(($money>= 50) && $money <= 50000)
             echo 'something else';
    In case you have problems, try that way.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •