Jump to content

Multi-dimensional array for load data MYSQL


Zafire

Recommended Posts

Hi, i need to create multi-dimensional arrays for load data of a player from a mysql table i have 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 
----------------------------------------------------------------------------------------------- 
  

but it doesnt works, i think you understand me i want to load data of a player so i need something like data[player]["money"].. i have to use that player because if something login and his name is Maria i use data["Maria"]["money"].. if i dont use that array for everyonee single user, will be buggy because will be the same var for all..

Help me pls, thx god bless u

Link to comment

What do you need to do is make a table as dictionaires.

You can read about it here:

http://lua-users.org/wiki/TablesTutorial

Then would be something like:

t = { maria="hermoneyhere", darklink="hismoneyhere", john="hismoneyhere" }

Then guess you want to print the money of all players?

Something like:

  
for k,v in pairs(t) do  
     outputChatBox(k .. " has this money: " .. v) 
end 
  

Then would appear on console something like:

maria has this money: 233 --int depending on his money, can be a data node of the player.

darklink has this money: 712

john has this money: 100

ofc I am the richest :b

I hope I could help you.

PS: I think you are portuguese? maybe brasil?

Link to comment

thxx for help!! but i try and try before you help me and i create i function for take a single data for the player i want i use this..

  
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 
  

jeje, i am from Venezuela :D

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...