Quick & Dirty Question Regarding Variable Usage in Tables

So this should be a very simple ‘yes’ or ‘no.’ Or in coding terms a ‘0’ or ‘1’. B)

I have a lua table:

     myTable = {}

I have one row in the table with 6 columns:

     myTable[1].myColumn1

     myTable[1].myColumn2

     myTable[1].myColumn3

          etc . . . 

Can I create a variable for the column name?   ex . . .

If I wanted to print all the column data, the way I see it working would be:

for z=1,6 do

 print("My Column Data= "…myTable[1].myColumn…z)

end

But that doesn’t work.  

Is this possible?  If so, please explain.  

Thanks!

First of all to have multiple columns you need to make each row a table too:

myTable = {}

myTable[1] = {}

Then you can have:

myTable[1].column1 = somevalue

Lua supports two ways to access that data:

myTable[1].column1

or

myTable[1][“column1”]

Either syntax will work.  The 2nd method allows you to create strings that would be variables:

whichCol  = “column” … tostring(z)

print(“My Column Data=” … myTable[1][whichCol]

thank you!  

First of all to have multiple columns you need to make each row a table too:

myTable = {}

myTable[1] = {}

Then you can have:

myTable[1].column1 = somevalue

Lua supports two ways to access that data:

myTable[1].column1

or

myTable[1][“column1”]

Either syntax will work.  The 2nd method allows you to create strings that would be variables:

whichCol  = “column” … tostring(z)

print(“My Column Data=” … myTable[1][whichCol]

thank you!