mccragge Posted April 23, 2009 Share Posted April 23, 2009 Ok here is my problem, I want the following function to display the information in bold red text on another page when the function is called into use. How do I go about formatting it correctly? +_+_+_+_+_+_+_+_+ function all_skillsup($action,$lang_fun) { if ($action == "magic_attack") { $ret=$this->skillup("wisdom"); if ($ret==1){ $_SESSION['disp_msg'][] = $lang_fun["gai_wis"]; } } else { if ($this->weapon==0){ $ret=$this->skillup("weaponless"); if ($ret==1){ $_SESSION['disp_msg'][] = $lang_fun["gai_wep"]; } } else { $ret=$this->skillup("fight"); if ($ret==1){ $_SESSION['disp_msg'][]= $lang_fun["gai_att"]; } $ret=$this->skillup("defence"); if ($ret==1){ $_SESSION['disp_msg'][]= $lang_fun["gai_def"]; } } } } +_+_+_+_+_+_+_+ Thanks for any help, I know this has got to be a simple problem, but I am such a noob I can't seem to get it to work. McCragge Quote Link to comment https://forums.phpfreaks.com/topic/155314-simple-problem-with-functions/ Share on other sites More sharing options...
laffin Posted April 23, 2009 Share Posted April 23, 2009 learn to use elseif's I see a lot of else statement immediately followed by an if statement, however I dun see the logic behind this and u dun really use $ret, u define it, use it in an expression than redefine it. U have: if ($action == "magic_attack") { $ret=$this->skillup("wisdom"); if ($ret==1){ $_SESSION['disp_msg'][] = $lang_fun["gai_wis"]; } wuts the difference? if ($action == "magic_attack" && (($this->skillup("wisdom")) ==1) { $_SESSION['disp_msg'][] = $lang_fun["gai_wis"]; } two if statements right in succession can be placed into one if statement, with the AND (&&) OR (||) operators. since $ret isnt really used for anything, we can remove the definition, and put it directly into the expression Quote Link to comment https://forums.phpfreaks.com/topic/155314-simple-problem-with-functions/#findComment-817120 Share on other sites More sharing options...
mccragge Posted April 23, 2009 Author Share Posted April 23, 2009 First off I didn't write the original code, but that is certainly great advice and I will change it to that immediately, but, it still doesn't answer my question of getting it to display the information in bold red text on another page when the function is called into use. How do I go about formatting it correctly? McCragge Quote Link to comment https://forums.phpfreaks.com/topic/155314-simple-problem-with-functions/#findComment-817121 Share on other sites More sharing options...
DarkSuperHero Posted April 23, 2009 Share Posted April 23, 2009 it should be as simple as: <?php echo('<b><span style="color:#FF0000;"'>$_SESSION['disp_msg'][0]'</span></b>'); although, it looks like the function just sets up some information in the sessions variable...the way you would output the information in the sessions variabels would be independent of the function itself.....I think you might be after something else rather than this function....and I don't think "else if" statements are needed here... Quote Link to comment https://forums.phpfreaks.com/topic/155314-simple-problem-with-functions/#findComment-817138 Share on other sites More sharing options...
mccragge Posted April 24, 2009 Author Share Posted April 24, 2009 Do I insert that code you showed as an example in the above function code that I posted in the original message or do i put it where the function is used elsewhere on the website? McCragge Quote Link to comment https://forums.phpfreaks.com/topic/155314-simple-problem-with-functions/#findComment-818094 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.