Cassandra Posted April 6, 2012 Share Posted April 6, 2012 I am having a problem regarding the dbPoll's result and getAllElementData. So, here is it. setElementData(player, "loggedin", 0) setElementData(player, "posx", 0.0) setElementData(player, "posy", 0.0) setElementData(player, "posz", 0.0) These are my elements. This is my mysql table structure. 1 username varchar(24) 2 password varchar(70) 3 ip varchar(16) 4 posx float 5 posy float 6 posz float Now, what I want to do is to loop my elements and query an update on the mysql table. How would I be able to do that? How to ignore username, password and ip from the result loop and loggedin from the element data loop? Link to comment
Castillo Posted April 6, 2012 Share Posted April 6, 2012 local skipData = { [ "username" ] = true, [ "password" ] = true, [ "loggedin " ] = true } function getMyData ( thePlayer ) local data = getAllElementData ( thePlayer ) for dataName, dataValue in pairs ( data ) do if ( not skipData[ dataName ] ) then outputChatBox ( dataName ..": ".. dataValue ) end end end addCommandHandler ( "mydata", getMyData ) Is that what you meant? Link to comment
Cassandra Posted April 6, 2012 Author Share Posted April 6, 2012 local skipData = { [ "username" ] = true, [ "password" ] = true, [ "loggedin " ] = true } function getMyData ( thePlayer ) local data = getAllElementData ( thePlayer ) for dataName, dataValue in pairs ( data ) do if ( not skipData[ dataName ] ) then outputChatBox ( dataName ..": ".. dataValue ) end end end addCommandHandler ( "mydata", getMyData ) Is that what you meant? You solved my first problem thanks. Now, how to do the same thing with result on dbPoll? Link to comment
Jaysds1 Posted April 6, 2012 Share Posted April 6, 2012 (edited) srry, wrong code Edited April 6, 2012 by Guest Link to comment
Castillo Posted April 6, 2012 Share Posted April 6, 2012 @Jaysds1: Is that a joke? or you're just increasing your post count? because that'll never work. @Cassandra: You can get all the column names of a table with this: addCommandHandler ( "columnnames", function ( ) local descQuery = dbQuery ( connection, "DESCRIBE ??", "myTable" ) local descResult = dbPoll ( descQuery, -1 ) for _, column in ipairs( descResult ) do outputChatBox ( tostring ( column.Field ) ) end end ) Link to comment
Cassandra Posted April 6, 2012 Author Share Posted April 6, 2012 @Jaysds1: Is that a joke? or you're just increasing your post count? because that'll never work.@Cassandra: You can get all the column names of a table with this: addCommandHandler ( "columnnames", function ( ) local descQuery = dbQuery ( connection, "DESCRIBE ??", "myTable" ) local descResult = dbPoll ( descQuery, -1 ) for _, column in ipairs( descResult ) do outputChatBox ( tostring ( column.Field ) ) end end ) I have already found a way with your first solution. Thanks again and apologize for not responding. Link to comment
Castillo Posted April 6, 2012 Share Posted April 6, 2012 It's ok, we're all busy . You're welcome . 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