HeavyMetal Posted February 13, 2013 Share Posted February 13, 2013 im with some problems here, i have a database witch have the player name, and a number related to it, everytime i use: result = executeSQLQuery("SELECT Name FROM owners WHERE Dim=?", 1) it work nice in the code but when i need to read this using a chat box: outputChatBox("Welcome "..tostring(result).."",player)] it says: Welcome table: 045D8820 how can i return the real value, and not a "table"? Link to comment
csiguusz Posted February 13, 2013 Share Posted February 13, 2013 If you like to read and learn yourself: https://wiki.multitheftauto.com/wiki/ExecuteSQLQuery If not, try: tostring( result[1].Name ) Link to comment
HeavyMetal Posted February 13, 2013 Author Share Posted February 13, 2013 (edited) i already saw this page,but im having the problem when i use what says on it, anyway, what means when a variable haves # before it? i know that is something related to tables, but what exactly this does? Edited February 13, 2013 by Guest Link to comment
HeavyMetal Posted February 13, 2013 Author Share Posted February 13, 2013 thanks, and you know how to retrieve the value of a table? and not its location code? Link to comment
csiguusz Posted February 13, 2013 Share Posted February 13, 2013 You can count a table's elements with the #. Link to comment
iPrestege Posted February 13, 2013 Share Posted February 13, 2013 Yes ^ But You Can Stop it . Link to comment
csiguusz Posted February 13, 2013 Share Posted February 13, 2013 What do you mean by 'stopping' a table? Link to comment
HeavyMetal Posted February 13, 2013 Author Share Posted February 13, 2013 i dont want to be annoying but, how to get the value? and not table: 045D8820 from a table? anyway to convert this table code into the value? any function for that? thanks Link to comment
csiguusz Posted February 13, 2013 Share Posted February 13, 2013 I think I've alredy told this you in my first post. And to learn how lua tables work: http://lua-users.org/wiki/TablesTutorial Link to comment
HeavyMetal Posted February 13, 2013 Author Share Posted February 13, 2013 i know i tryed what u said in your first post, but i didnt understand what u mean, "result[1].Name", what is this function? what comes in the []? what goes on the front and what goes after the ".", dont forget, when someone asks something, is because they dont know, i will not understand without someone explaining what each part of the function means and how it can help on my problem. thanks Link to comment
Castillo Posted February 13, 2013 Share Posted February 13, 2013 What goes inside the [ ] is the row index, and what goes after the dot is the column name. Link to comment
csiguusz Posted February 13, 2013 Share Posted February 13, 2013 (edited) It's hard to completly explain how tables work, that's why i gave you a link. In the brackets is the index of the table 1 means the first entry in the table. In this case this first entry is the first (and in this case the only ) returned row from the database. This is also a table (yes a table inside of an another : ) ) and it contains all the data of this row, the names of the keys of the this table are equal to the colum names in the database, and the values are the values of the of those colums in the given row . After the dot comes a name of a key from the second table, wiches value you want to get. Edited February 13, 2013 by Guest Link to comment
HeavyMetal Posted February 13, 2013 Author Share Posted February 13, 2013 ok thanks, it is working now Link to comment
Anderl Posted February 13, 2013 Share Posted February 13, 2013 i dont want to be annoying but, how to get the value? and not table: 045D8820 from a table? anyway to convert this table code into the value? any function for that? thanks When you try to output a table it does show its ID, you must call a member (something that is inside the table): local myTable = {}; --now here we're going to try to output the table outputChatBox ( myTable ); -- it's going to output its ID --now we'll add something to the table myTable[1] = "Lua is so awesome."; -- this is going to set the value of the index (call it 'slot', if that's easier for you to understand) 1 to the string "Lua is so awesome." --okay, let's output the value of the index 1 outputChatBox ( myTable[1] ); -- it's going to output "Lua is so awesome." Hope you got it 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