Page 1 of 1
Function/Variable Problem (Just Need Solution)
Posted: Wed Feb 09, 2011 2:32 pm
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
Re: Function/Variable Problem
Posted: Wed Feb 09, 2011 3:32 pm
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...
Re: Function/Variable Problem (Problem Found just need solut
Posted: Wed Feb 09, 2011 3:53 pm
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?