Jump to content

How to really return a something out of a table?


HeavyMetal

Recommended Posts

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

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

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 by Guest
Link to comment
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 :P

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