Jump to content

dbPoll?


GTX

Recommended Posts

Posted

Hello, I'm making a 'custom' poll function. I have problem with return thingy...

So, code looks like:

  
function poll(resultid) 
    local result, num_affected_rows, errmsg = dbPoll(resultPool[resultid], -1) 
    if not result then 
        outputDebugString("Error: "..errmsg) 
        return false 
    end 
    local resulta = {} 
    for result, row in pairs(result) do 
        for column, value in pairs(row) do 
            resulta[column] = value 
        end 
    end 
    return resulta, num_affected_rows 
end 
  

Everything is fine. But now, here comes the problem. It returns only 1 row. So, my query looks like that:

  
local query = exports.mysql:query("SELECT * FROM characters WHERE account='"..accID.."'") 
  

This query selects 2 rows. But when I use dbPoll, it returns only 1! I want it to return ALL selected rows.

Thanks in advance.

Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS.

Developer and owner of

https://projectbea.st - Project Beast
Posted
    local resulta = {} 
    for result, row in pairs(result) do 
        for column, value in pairs(row) do 
            resulta[column] = value 
        end 
    end 

What is that for? "result" already returns a table like this:

column: value

function poll(resultid) 
    local result, num_affected_rows, errmsg = dbPoll(resultPool[resultid], -1) 
    if ( not result ) then 
        outputDebugString("Error: "..errmsg) 
        return false 
    end 
  
    return result, num_affected_rows 
end 

Try that.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

I don't want to send it directly. Currently, I am getting values like:

  
local result, affected = exports.mysql:poll(query) 
outputChatBox(result["id"]) 
  

I don't want to change the whole gamemode for that...

Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS.

Developer and owner of

https://projectbea.st - Project Beast
Posted

And this is the query?

local query = exports.mysql:query("SELECT * FROM characters WHERE account='"..accID.."'") 

If so, then try this:

local query = exports.mysql:query("SELECT * FROM characters WHERE account='"..accID.."'") 
local result, affected = exports.mysql:poll(query) 
for _, char in ipairs ( result ) do 
outputChatBox ( char [ "id" ] ) 
end 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

I don't want to do a loop in a script, I want to do it in the mysql script already.

Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS.

Developer and owner of

https://projectbea.st - Project Beast
Posted

You seem not to understand, with your loop at mysql script, you would also need to loop it at your script to get all the results.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

No... Look, I've got a problem in returning a table... For example: I've got 2 rows and I select them with query. Then when I want to use exports.mysql:poll, this returns only 1 row, but it must return 2 rows.

Row #1: abc

Row #2: def

outputChatBox(result["id"]) --> def

Is it possible to return 2 times?...

Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS.

Developer and owner of

https://projectbea.st - Project Beast
Posted

On your script, you are replacing the values everytime, since you are doing:

column = value

which means, when it gets the second one, it'll replace the other one.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Then how shall I do it?

Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS.

Developer and owner of

https://projectbea.st - Project Beast
Posted

You can use this:

function poll(resultid) 
    local result, num_affected_rows, errmsg = dbPoll(resultPool[resultid], -1) 
    if ( not result ) then 
        outputDebugString("Error: "..errmsg) 
        return false 
    end 
  
    return result, num_affected_rows 
end 

Then on your script:

local query = exports.mysql:query("SELECT * FROM characters WHERE account='"..accID.."'") 
local result, affected = exports.mysql:poll(query) 
outputChatBox ( result [ 1 ] [ "id" ] ) 
outputChatBox ( result [ 2 ] [ "id" ] ) 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

It doesn't work. No errors. No outputs;

  
local query = mysql:query("SELECT * FROM characters WHERE account='"..accID.."'") 
if query then 
    local result, num_affected_rows = mysql:poll(query) 
    if num_affected_rows > 0 then 
        outputChatBox(result[1]["charactername"]) 
    end 
end 
  

Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS.

Developer and owner of

https://projectbea.st - Project Beast
Posted

What does "num_affected_rows" return?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

The number of rows.

Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS.

Developer and owner of

https://projectbea.st - Project Beast
Posted

I know that, but I mean, what number does it say?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

Ahh, now I fixed it. The problem was in accID, it was returning false. Thanks for helping me!

Do you require a paid scripter? Contact me! (Unavailable) Currently I am experienced in Lua, PHP, HTML, CSS, SQL and JS.

Developer and owner of

https://projectbea.st - Project Beast
Posted

You're welcome.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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...