Jump to content

Can't seem to find a solution


Recommended Posts

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
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
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: 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
@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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...