Jump to content


Photo

PHP Help (Simple)


  • Please log in to reply
3 replies to this topic

#1 babskool

babskool
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 12 October 2006 - 06:03 PM

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

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 12 October 2006 - 06:08 PM

Rather than using echo in the country function use a variable and retrun the variable:
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();

?>
The code used is an adaptation of Kens code.


#3 babskool

babskool
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 12 October 2006 - 06:11 PM

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


Please let me know..


Thanks,


#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 12 October 2006 - 06:29 PM

Yeah the following:
$message.="Country $country_name";

Should work fine.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users