Function/Variable Problem (Just Need Solution)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Starkid225
Forum Newbie
Posts: 9
Joined: Mon Feb 07, 2011 10:28 pm

Function/Variable Problem (Just Need Solution)

Post by Starkid225 »

I have two functions in my script I need a variable from one function to be sent to another. Part of my code is below:

Code: Select all

function CheckTime() 
{
echo $this->turns; // I need this variable from RaidVillage function
}

function RaidVillage()
{
//Variables
$get_turns = mysql_query("SELECT turns FROM users WHERE id = '".$_SESSION["id"]."'");
$turns = mysql_fetch_assoc($get_turns);
$this->time = $_POST["raidtime"];
$this->turns = $_POST["raidtime"]/30; // I need this variable to be echoed in the CheckTime function above. How can I do this?
$this->from = time();
$this->to = $this->from + $this->time;
}
Hope someone can help me....

Thanks,
Starkid225
Last edited by Starkid225 on Wed Feb 09, 2011 7:02 pm, edited 1 time in total.
anantha
Forum Commoner
Posts: 59
Joined: Thu Dec 23, 2010 7:38 pm

Re: Function/Variable Problem

Post by anantha »

Code: Select all

function CheckTime() 
{
echo $this->RaidVillage(); // I need this variable from RaidVillage function
}

function RaidVillage()
{
//Variables
$get_turns = mysql_query("SELECT turns FROM users WHERE id = '".$_SESSION["id"]."'");
$turns = mysql_fetch_assoc($get_turns);
$this->time = $_POST["raidtime"];
$this->turns = $_POST["raidtime"]/30; // I need this variable to be echoed in the CheckTime function above. How can I do this?
$this->from = time();
$this->to = $this->from + $this->time;

return $this->turns;
}



since you are using $this...those variable should already be there..but i am not sure why u r not getting it.....you can return the value like above and get it...there are number of ways to do...
Starkid225
Forum Newbie
Posts: 9
Joined: Mon Feb 07, 2011 10:28 pm

Re: Function/Variable Problem (Problem Found just need solut

Post by Starkid225 »

I figured out why it wont work but i dont know how to fix it. My problem is that i have two different functions passing variables to one function and it cant find 4th argument. I have commented out my problem in the php code below:

Code: Select all

function CheckTime($timeLeft, $raidData, $creature, $this->turns) 
{

//Trying to get $this->turns variable from RaidVillage function to I can echo it here.

}

function RaidVillage()
{
//Variables
$get_turns = mysql_query("SELECT turns FROM users WHERE id = '".$_SESSION["id"]."'");
$turns = mysql_fetch_assoc($get_turns);
$this->time = $_POST["raidtime"];
$this->turns = $_POST["raidtime"]/30; 
$this->CheckTime($this->turns); //thinks of this as a argument one and not a argument 4 because there is only one variable here but the other three are being sent by another function called CheckRaid.

$this->from = time();
$this->to = $this->from + $this->time;
}

function CheckRaid() 
{

//Variables
$this->Init();
$village = mysql_query("SELECT * FROM village_raids WHERE uid = '".$_SESSION["id"]."' AND active = 1");

If (mysql_num_rows($village) == 1)
{
$this->raid = mysql_fetch_assoc($village);
$this->TimeLeft = $this->raid[rto] - time();
$this->CheckTime ($this->TimeLeft, $this->raid, $this->creature); // Here are the first three arguments for CheckTime(). These work but the 4th one i try to add in using another function does not work and says it is missing the argument.
} else {
$get_turns = mysql_query("SELECT turns FROM users WHERE id = '".$_SESSION["id"]."'");
$turns = mysql_fetch_assoc($get_turns);
}
}
Does anybody know a solution?
Post Reply