Jump to content

SQL data in grid


Crosshair

Recommended Posts

Hello.

I want to fetch some data from sql and add in the gui but is not working.

addEvent("nume", true) 
addEventHandler("nume", getRootElement(), function(team) 
    local teamstr = getTeamName(team) 
    local sql = mysql:query("SELECT `username` FROM `accounts` WHERE `factiune` = '"..teamstr.."'") 
    if (sql) then 
        while true do 
            local row = mysql:fetch_assoc(sql) 
            if (not row) then break end 
            local jucatori = row["username"] 
            setElementData(source, "jucatori", jucatori) 
        end 
        mysql:free_result(sql) 
    end 
end) 

if i debug row["username"] it returns all those users that has my team.

  
grid = guiCreateGridList(9,29,467,379,false,meniu) 
local nume = guiGridListAddColumn(grid,"Nume",0.2) 
local team = getPlayerTeam(getLocalPlayer()) 
if (team) then 
    local players = getPlayersInTeam(team) 
    for k, v in ipairs(players) do 
        triggerServerEvent("nume", getLocalPlayer(), team) 
        local row = guiGridListAddRow(grid) 
        guiGridListSetItemText(grid, row, nume, getElementData( localPlayer, "jucatori"), false, false) 
    end 
end 

in grid only shows one user.

Link to post

Try this:

-- client side:

grid = guiCreateGridList(9,29,467,379,false,meniu) 
local nume = guiGridListAddColumn(grid,"Nume",0.2) 
local team = getPlayerTeam ( localPlayer ) 
if ( team ) then 
    triggerServerEvent ( "nume", localPlayer, team ) 
end 
  
addEvent ( "returnUsers", true ) 
addEventHandler ( "returnUsers", root, 
    function ( users ) 
        for index, user in ipairs ( users ) do 
            local row = guiGridListAddRow ( grid ) 
            guiGridListSetItemText ( grid, row, nume, user [ "username" ], false, false ) 
        end 
    end 
) 

-- server side:

addEvent ( "nume", true ) 
addEventHandler ( "nume", getRootElement(), 
    function ( team ) 
        local teamstr = getTeamName ( team ) 
        local sql = mysql:query ( "SELECT `username` FROM `accounts` WHERE `factiune` = '".. teamstr .."'" ) 
        if ( sql ) then 
            triggerClientEvent ( source, "returnUsers", source, sql ) 
        end 
        mysql:free_result ( sql ) 
    end 
) 

Link to post
  • Other Languages Moderators
You can try this:
triggerClientEvent ( source, "returnUsers", source, mysql:fetch_assoc ( sql ) ) 

It's wrong. By logic you can't use this because your self ( mysql ) is connection ( not query ).

triggerClientEvent ( source, "returnUsers", source, sql:fetch_assoc( ) ) 

Link to post
You can try this:
triggerClientEvent ( source, "returnUsers", source, mysql:fetch_assoc ( sql ) ) 

It's wrong. By logic you can't use this because your self ( mysql ) is connection ( not query ).

triggerClientEvent ( source, "returnUsers", source, sql:fetch_assoc( ) ) 

How I'm supposed to know how his resource to manage MySQL queries work?

Link to post

How about this ?

function sql(thePlayer) 
team = getPlayerTeam(thePlayer) 
teamstr = getTeamName(team) 
local sql = mysql:query("SELECT `username` FROM `accounts` WHERE `factiune` = '"..teamstr.."'") 
    if (sql) then 
        while true do 
            row = mysql:fetch_assoc(sql) 
            if (not row) then break end 
            jucatori = row["username"] 
            triggerClientEvent(source, "factiunemeniu", getRootElement(), jucatori) 
        end 
        mysql:free_result(sql) 
    end 
end 
addEventHandler("onPlayerJoin", getRootElement(), sql) 
  

function factiunemeniu(jucatori) 
meniu = guiCreateWindow(233,164,600,440,"Meniu factiune",false) 
grid = guiCreateGridList(9,29,467,379,false,meniu) 
local nume = guiGridListAddColumn(grid,"Nume",0.2) 
outputDebugString(jucatori) 
    for k, v in ipairs (jucatori) do 
        local row = guiGridListAddRow(grid) 
        guiGridListSetItemText(grid, row, nume, jucatori, false, false) 
    end 
end 
addEvent("factiunemeniu", true) 
addEventHandler("factiunemeniu", getRootElement(), factiunemeniu) 

On outputDebugString(jucatori) returns nil. In server side the debug shows

Link to post
meniu = guiCreateWindow(233,164,600,440,"Meniu factiune",false) 
grid = guiCreateGridList(9,29,467,379,false,meniu) 
local nume = guiGridListAddColumn(grid,"Nume",0.2) 
  
function factiunemeniu(jucatori) 
    local row = guiGridListAddRow(grid) 
    guiGridListSetItemText(grid, row, nume, jucatori, false, false) 
end 
addEvent("factiunemeniu", true) 
addEventHandler("factiunemeniu", getRootElement(), factiunemeniu) 

Link to post

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