Zafire Posted July 24, 2011 Share Posted July 24, 2011 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
qaisjp Posted July 24, 2011 Share Posted July 24, 2011 maybe try and configure it to do this: zafire[player]["money"] Link to comment
Zafire Posted July 24, 2011 Author Share Posted July 24, 2011 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 Link to comment
Castillo Posted July 25, 2011 Share Posted July 25, 2011 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
Zafire Posted July 25, 2011 Author Share Posted July 25, 2011 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
Castillo Posted July 25, 2011 Share Posted July 25, 2011 You are messing my head o_O, I don't understand anything now... Link to comment
Zafire Posted July 25, 2011 Author Share Posted July 25, 2011 You are messing my head o_O, I don't understand anything now... hahahahahaha !!!! 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
Castillo Posted July 25, 2011 Share Posted July 25, 2011 So... you fixed it? if so, no need to make my head about to explode o_O. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now