Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
Register FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 01-09-2002, 02:55 AM
Knoman's Avatar
Knoman Knoman is offline
 
Join Date: Oct 2001
Posts: 74
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

heh, I'm stumped. I cant seen to get this function to work right.

PHP Code:
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.
Reply With Quote
  #2  
Old 01-09-2002, 06:18 AM
Mark Hensler's Avatar
Mark Hensler Mark Hensler is offline
 
Join Date: Oct 2001
Location: California
Posts: 205
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You have to define $stat as global in your function,
PHP Code:
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.
PHP Code:
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"); 
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:25 AM.


Powered by vBulletin® Version 3.9.0
Copyright ©2000 - 2017, vBulletin Solutions Inc.