Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/155314-simple-problem-with-functions/
Share on other sites

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

 

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

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...

 

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.