Crosshair Posted June 18, 2012 Share Posted June 18, 2012 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 comment
Castillo Posted June 18, 2012 Share Posted June 18, 2012 Of course, because you're overwritting the same element data over and over, you should create a table and insert each user then set that table as element data. Link to comment
Crosshair Posted June 18, 2012 Author Share Posted June 18, 2012 You mean change setElementData(source, "jucatori", jucatori) to setElementData(source, "jucatori", row) ? This will give me a warning that guiGridListSetItemText expects string and not a table. Link to comment
Castillo Posted June 18, 2012 Share Posted June 18, 2012 Well, from my point of view, that script makes no sense, you're looping all the players in the team of the local player and get his team, the loop is completely useless. Link to comment
Crosshair Posted June 18, 2012 Author Share Posted June 18, 2012 Can you help me fix it then ? The script should get my team name, search for the players that has the same team and put them in a gridlist Link to comment
Castillo Posted June 18, 2012 Share Posted June 18, 2012 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 comment
Crosshair Posted June 18, 2012 Author Share Posted June 18, 2012 bad argument at ipairs. Table expected, got number Link to comment
Castillo Posted June 18, 2012 Share Posted June 18, 2012 Huh? mysql:query ( "SELECT `username` FROM `accounts` WHERE `factiune` = '".. teamstr .."'" ) That should return a table with users matching that team, not a number? Link to comment
Crosshair Posted June 18, 2012 Author Share Posted June 18, 2012 Yes. Should i use fetch_assoc ? Link to comment
Castillo Posted June 18, 2012 Share Posted June 18, 2012 You can try this: triggerClientEvent ( source, "returnUsers", source, mysql:fetch_assoc ( sql ) ) Link to comment
Crosshair Posted June 18, 2012 Author Share Posted June 18, 2012 No warning but shows only one result. Link to comment
Kenix Posted June 18, 2012 Share Posted June 18, 2012 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 comment
Crosshair Posted June 18, 2012 Author Share Posted June 18, 2012 Still nothing. Got only one result. Link to comment
Kenix Posted June 18, 2012 Share Posted June 18, 2012 Still nothing. Got only one result. ? Link to comment
Crosshair Posted June 18, 2012 Author Share Posted June 18, 2012 To be more precise: http://i.imgur.com/j5Pc1.png Add those in a gridlist Link to comment
Castillo Posted June 19, 2012 Share Posted June 19, 2012 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 comment
Crosshair Posted June 19, 2012 Author Share Posted June 19, 2012 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 comment
Castillo Posted June 19, 2012 Share Posted June 19, 2012 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 comment
Crosshair Posted June 19, 2012 Author Share Posted June 19, 2012 Expected string, got nil at "jucatori" Link to comment
Castillo Posted June 20, 2012 Share Posted June 20, 2012 Then what you're trying to send from server side is a nil value. Link to comment
Crosshair Posted June 20, 2012 Author Share Posted June 20, 2012 But it`s not. If i put outputDebugString(jucatori) in server side returns the values. 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