Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8877263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:25:37+00:00 2026-06-14T19:25:37+00:00

How do you return an array from a sqlite database in lua? I have

  • 0

How do you return an array from a sqlite database in lua?

I have this sameple code here:

function getMoveName()
    tempMoveName = {}
    for row in db:nrows("SELECT * FROM movetable") do
        tempMoveName = row.movename .. " " .. row.totalcubicfeet .. " " .. row.totalitem .. "\n"
    end
    return tempMoveName
end

which will return the content of the database and then print the content with this line of code:

local displaymovenames = mydatabase.getMoveName()

print ( displaymovenames )

however it only returns the last data and not all of the contents of it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T19:25:38+00:00Added an answer on June 14, 2026 at 7:25 pm

    What you are doing is for every row, you just store the row data in the variable tempMoveName and hence overwriting the previous value.

    You need to add the rowData to the table tempMoveName.

    function getMoveName()
        tempMoveName = {}
        for row in db:nrows("SELECT * FROM movetable") do
            local rowData = row.movename .. " " .. row.totalcubicfeet.." "..row.totalitem.."\n"
            tempMoveName[#tempMoveName+1] = rowData
        end
        return tempMoveName
    end
    

    EDIT

    To access the table elements you have to do the following

    for i=1,#tempMoveName do 
       print(tempMoveName[i]) 
    end
    

    note that #tempMoveName gives the length of the table(i.e no. of elements in the table)

    P.S if you are going to do a lot of coding in Lua, I’d suggest you get a grip on the basics of Tables, cos table is the main datatype of Lua. Arrays, lists, dictionaries, classes and almost everything are implemented via tables. Here is a tutorial for a start!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array populated with input from an SQLite database. When I use
Is there any way to return an array from a function? More specifically, I've
I'm trying to return the ajax success array from one function to another. For
$result = mysql_query(SELECT * FROM project ORDER BY projectid); while($row = mysql_fetch_array($result)) { return(array($row['projectid'],
I have the following code in config: <?php return array( 'di' => array( 'instance'
I have a database manager which successfully loads a string from my sqlite database,
I have an events app which gets events data from sqlite database and displays
My application have to load some points from internal sqlite database of android, and
I have an SQLite database from which I need to delete records periodically. What
I have spinner which I populate from SQLite database. But I want to populate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.