0
在lua中显示数组时,它总是以1开头,所以如果我使用select * from ...
作为table.id
的引用,则在我的sql查询中使用它。我现在的问题是如果table.id
的sql查询不会以1开头,或者它会像[3,5,6, ...]
那样?lua中的数组索引
我的代码是这样的,
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
这样的row.id
输出是[3,5,6,..]因为我使用的row.id
作为数组data
的索引。
我的问题是我应该怎么做或使用,以便阵列data
的索引将变成这样,[1,2,3,....]?