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

  • Home
  • SEARCH
  • 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 7935673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:59:40+00:00 2026-06-03T21:59:40+00:00

in displaying an array in lua, it always start with 1, so i used

  • 0

in displaying an array in lua, it always start with 1, so i used it in my sql query if i am using select * from ... as reference of table.id . my problem now is what if the sql query of table.id will not start with 1, or it will be like [3,5,6, ...]?

my code is like this,

local data = {}

for row in db:nrows("SELECT song.id as id, song.title as song, artist.name as artist, genre.name as genre, album.title as album FROM song, artist, genre, album WHERE song.artist_id = artist.id AND song.genre_id = genre.id AND song.album_id = album.id AND song.duration = 120.00") do
                        data[row.id] = {}
                        data[row.id].song = row.song
                        data[row.id].artist = row.artist
                        data[row.id].genre = row.genre
                        data[row.id].album = row.album
end

so the output of row.id is [3,5,6, ..] because i used the row.id as the index of the array data.

my question is what should i do or use so that the index of array data will become like this, [1,2,3,….]?

  • 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-03T21:59:41+00:00Added an answer on June 3, 2026 at 9:59 pm

    You can just use an index variable:

    local data = {}
    local next = 1
    
    for row in db:nrows("SELECT song.id as id, song.title as song, artist.name as artist, genre.name as genre, album.title as album FROM song, artist, genre, album WHERE song.artist_id = artist.id AND song.genre_id = genre.id AND song.album_id = album.id AND song.duration = 120.00") do
        data[next] = row
        next = next + 1
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting a string array from command line and displaying it to user as
I am using the following method for displaying the multiple select box and it
I'm displaying a ListView of files to be played, read from an array in
i am displaying array of data in a table view. my code for that
I am getting information from an array and displaying the results in a text
This is a multidimensional array I got from Google Calendar for displaying events. Array
I have this array that I am displaying with a table how can i
Hello I need help with displaying data from 2 table. So i Have 2
Lets say I have an array $aSomeArray = array(1,2,3,4,5,6,7,8,9,10,11,12); Now displaying one array value
I have a Gridview displaying buttons that get their content from an array, I

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.