How do I retrieve the number of items in a table? [import]uid: 8697 topic_id: 30608 reply_id: 330608[/import]
[lua]table.getn(myTable)[/lua]
[import]uid: 147305 topic_id: 30608 reply_id: 122648[/import]
That’s fine if you’ve extracted the data from the database table to a separate table but I just want to query the database to find the number of items in a table in the database. [import]uid: 8697 topic_id: 30608 reply_id: 122655[/import]
Yup… somehow i forgot the thread title when i read your main message… you would need to do a count(*) in the sql statement. Below is an example from one of my projects(with some fluff code taken out).
[lua]for row in db:nrows(“select count(*) “LevelCount” from levels where level =”…iLevel) do
– row.LevelCount will give the total number of records matching my sql query
print(row.LevelCount)
end[/lua]
If you just wanted to do the statement without any clause just remove the where level = stuff… and of course put in your own table name. [import]uid: 147305 topic_id: 30608 reply_id: 122657[/import]
Awesome that works, thank you, I just didn’t want to extract 2500 entries into another table if I didn’t have to. [import]uid: 8697 topic_id: 30608 reply_id: 122662[/import]
[lua]table.getn(myTable)[/lua]
[import]uid: 147305 topic_id: 30608 reply_id: 122648[/import]
That’s fine if you’ve extracted the data from the database table to a separate table but I just want to query the database to find the number of items in a table in the database. [import]uid: 8697 topic_id: 30608 reply_id: 122655[/import]
Yup… somehow i forgot the thread title when i read your main message… you would need to do a count(*) in the sql statement. Below is an example from one of my projects(with some fluff code taken out).
[lua]for row in db:nrows(“select count(*) “LevelCount” from levels where level =”…iLevel) do
– row.LevelCount will give the total number of records matching my sql query
print(row.LevelCount)
end[/lua]
If you just wanted to do the statement without any clause just remove the where level = stuff… and of course put in your own table name. [import]uid: 147305 topic_id: 30608 reply_id: 122657[/import]
Awesome that works, thank you, I just didn’t want to extract 2500 entries into another table if I didn’t have to. [import]uid: 8697 topic_id: 30608 reply_id: 122662[/import]