kuba90pl Posted September 8, 2013 Share Posted September 8, 2013 Hey! I have problem with SQL. I cant get results from my DB (I know there is a record (i checkd this with num_rows(=1))) Here is my db schema: dbQuery(db,"CREATE TABLE IF NOT EXISTS avatar(id INT,name TEXT,pass TEXT,food INT,games INT,health INT,energy INT,money INT,time INT)") and here is my problem: function avatarLogin(player,login,pass) local query = dbQuery(db,"SELECT * FROM `avatar` WHERE `name` = ?",login) local result, num_affected_rows, errmsg = dbPoll ( query, -1 ) for i,id in ipairs (result) do for column,val in ipairs (id) do server.log(val[column]) end end end but i dont get anything from this ( i just know that num_affected_rows = 1 so there is a record in db but i cant get retrieve it). Help me please or give me some tip! Link to comment
DiSaMe Posted September 8, 2013 Share Posted September 8, 2013 Maybe that's because ipairs only iterates over the array part of the table (numeric keys), but the row uses strings as column identifiers? Try iterating using pairs instead. Link to comment
kuba90pl Posted September 8, 2013 Author Share Posted September 8, 2013 Please, can you give me some example? Link to comment
Castillo Posted September 8, 2013 Share Posted September 8, 2013 function avatarLogin ( player, login, pass ) local query = dbQuery ( db,"SELECT * FROM `avatar` WHERE `name` = ?", login ) local result, num_affected_rows, errmsg = dbPoll ( query, -1 ) for i, id in ipairs ( result ) do for column, val in pairs ( id ) do -- Here, you had to use "pairs" because the table is not indexed. server.log ( val [ column ] ) end end end Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now