Jump to content

[HELP] Variable NAME from another variable


Zafire

Recommended Posts

Hi, i need help with these y will use mysql_fetch_asocc(query) but i need the variable name for that come from another variable, so example here is my code

  
function cargarStats(usuario) 
    local query = "SELECT * FROM usuarios WHERE usuario="..usuario 
    local resultado = mysql_query(query) 
    dato = mysql_fetch_assoc(result) 
end 
  

Look, now when i use for example cargarStats(zafire)

i want my code work like something like this..

  
function cargarStats(zafire) 
    local query = "SELECT * FROM usuarios WHERE usuario="..zafire 
    local resultado = mysql_query(query) 
    zafire = mysql_fetch_assoc(result) 
end 
  

look at Zafire = mysql_fetch_assoc(result) so there i will have vars like zafire["money"]

the point of this is use that vars for every single player..

Link to comment

i use this

----------------------------------------- Cargar Stats ----------------------------------------

function cargarStats(usuario)

local resultado = mysql_query(coneccion_mysql, "SELECT * FROM usuarios WHERE usuario='"..usuario.."'")

dato[player] = mysql_fetch_assoc(resultado)

end

-----------------------------------------------------------------------------------------------

[code]

And dont work :S

Link to comment

Try something like this:

dato = {} 
  
function cargarStats(usuario) 
local resultado = mysql_query(coneccion_mysql, "SELECT * FROM usuarios WHERE usuario='"..usuario.."'") 
if not dato[player] then dato[player] = {} end 
dato[player] = mysql_fetch_assoc(resultado) 
end 

Btw, what's that "player" there?

Link to comment
Try something like this:
dato = {} 
  
function cargarStats(usuario) 
local resultado = mysql_query(coneccion_mysql, "SELECT * FROM usuarios WHERE usuario='"..usuario.."'") 
if not dato[player] then dato[player] = {} end 
dato[player] = mysql_fetch_assoc(resultado) 
end 

Btw, what's that "player" there?

thxx i want that for single player.. example a user name is "pedro" and i want to in a function use dato["pedro"]["money"]

for single player.. so if another player enter example "jose" use dato["jose"]["money] so dato["pedro"]["money"] and dato["jose"]["money] are not the same.. but if i use dato = mysql_fetch_assoc(resultado) will be a bug, because will be not a var for single player.. if u givemoney to player using dato["money"] maybe another player login.. and will use that money.. will be buggy..

but i fix this, using another thing is better

  
-------------------------------------- Stat del Usuario --------------------------------------- 
function stat(usuario, dato) 
    local resultado = mysql_query(coneccion_mysql, "SELECT * FROM usuarios WHERE usuario='"..usuario.."'") 
    local datos = mysql_fetch_assoc(resultado)   
    return datos[dato] 
end 
----------------------------------------------------------------------------------------------- 
  

this is better because i can use stat("pedro", "money) and this function make a Return of that value.. is perfect

Link to comment
You are messing my head o_O, I don't understand anything now...

hahahahahaha xD!!!!

i want create a function loading data for every single player.. so when in my code i use OnPlayerLogin giveplayermoney(data[player]["money"]) after load the data.. it works for every single player.. will work like this for "pedro" giveplayermoney(data["pedro"]["money]) will work like this for jose giveplayermoney(data["jose"]["money]).. (I know maybe that code is bad, its only for xplain it)..

and with the function i create i fix it.. because now i can do the same, and without loading ALL the data of the player.. and works for everysingle player like this.. giveplayermoney(stat(player, "money")) will work like this for "pedro" giveplayermoney(stat("player", "money")) and like this for jose giveplayermoney(stat("jose", "money"))

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...