PDA

View Full Version : Function Problem


Knoman
01-09-2002, 02:55 AM
heh, I'm stumped. I cant seen to get this function to work right.


function pullstats ($type) {
$result= mysql_query("SELECT * FROM user WHERE userid=1")
or die ("Query Failed");
$stat[$type]= (mysql_result($result,0,$type));
return $stat[$type];
}


pullstats ("username");
print $stat[$type];


if i were to pull it out of the function and define $type, it then works.

Mark Hensler
01-09-2002, 06:18 AM
You have to define $stat as global in your function,

function pullstats($type)
{
global $stat;
$result = mysql_query("SELECT * FROM user WHERE userid=1") or die ("Query Failed");
$stat[$type]= mysql_result($result, 0, $type);
}

pullstats("username");
print $stat["username"]; or use the return value to assign it to a var.

function pullstats($type)
{
$result = mysql_query("SELECT * FROM user WHERE userid=1") or die ("Query Failed");
return mysql_result($result, 0, $type);
}

print pullstats("username");