Jump to content

PHP Help (Simple)


babskool

Recommended Posts

Hey guys,
Below is my code

_________________________________________________________________________


function country() {
global $step3_country1;
if($step3_country1 == "1"){ echo"Brazil";
}elseif($step3_country1 == "2"){ echo"China";
}elseif($step3_country1 == "3"){ echo"Costa Rica";
}else{ echo"No Country Selected";
}
}

$country_name = country();

___________________________________________________________________________________

Now What if i want to display the result inside something like this: $message.="Country $country_name";


Please let me know..


Thanks,
Shawn  :)
Link to comment
Share on other sites

Rather than using echo in the country function use a variable and retrun the variable:
[code]function country()
{
    global $step3_country1;

    switch ($step3_country1)
    {
      case '1':
          $c = 'Brazil';
          break;
      case '2':
          $c = 'China';
          break;
      case '3':
          $c = 'Costa Rica';
          break;
      case '4':
          $c = 'India';
          break;
      case '5':
          $c = 'Ghana';
          break;
      case '6':
          $c = 'Kenya';
          break;
      case '7':
          $c = 'Nepal';
          break;
      case '8':
          $c = 'Peru';
          break;
      case '9':
          $c = 'South Africa';
          break;
      case '10':
          $c = 'Tanzania';
          break;
      case '11':
          $c = 'Thailand';
          break;
      case '12':
          $c = 'Sri Lanka';
          break;
      case '1':
          $c = 'Brazil';
          break;
      default:
          $c = 'No Country Selected';
    }

    return $c;
}

$country_name = country();

?>[/code]
The code used is an adaptation of Kens code.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.