Jump to content

Archived

This topic is now archived and is closed to further replies.

babskool

PHP Help (Simple)

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  :)

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
Now What if i want to display the result inside something like this: $message.="Country $country_name";


Please let me know..


Thanks,

Share this post


Link to post
Share on other sites
Yeah the following:
[code]$message.="Country $country_name";[/code]

Should work fine.

Share this post


Link to post
Share on other sites

×

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.