steadyfi Posted March 12, 2015 Share Posted March 12, 2015 Hello Can someone tell me how can I convert a table into a integer value ? I'm using SQL Select function and it returns me a table even if I check in a table where is only a SINGLE registry. When I say a single registry, i mean the Account Name doesn't get repeated, and that's what I'm checking for and then I get the rank. How can I transform this table into a number ? Long story short, how do I convert a table with a single element into a integer value ? I know I need to use: tonumber executeSQLQuery for if My Code: executeSQLQuery("SELECT rank FROM otplayers WHERE player=? AND team=?", getAccountName(getPlayerAccount(player)), getTeamName(getPlayerTeam(player))) Thanks Link to comment
JR10 Posted March 12, 2015 Share Posted March 12, 2015 If there is only one row returned then the table returned should look something like this: returned_tabke = { [1] = { ["rank"] = "RANK" } } Why are you still using executeSQLQuery? Use dbQuery instead. Link to comment
steadyfi Posted March 12, 2015 Author Share Posted March 12, 2015 If there is only one row returned then the table returned should look something like this: returned_tabke = { [1] = { ["rank"] = "RANK" } } Why are you still using executeSQLQuery? Use dbQuery instead. Thank you JR10 ! I'm using executeSQLQuery because I realised I don't need a private database and because my script is already completely Non-Functional from the change I made from Account Data to SQL + the table oriented Gridlist that shows all the players in the team including offline ones, now I need to fix all the functions and repair all the SQL + make the code more compact and better. Also speed is a problem. Conclusion: Everything is broken so there is no need to change db + registry.db is good enough Wish me luck Link to comment
JR10 Posted March 12, 2015 Share Posted March 12, 2015 db* functions are not slower in any way, so "speed" shouldn't be a problem. It's generally better that you create a private local database to the resources folder. Good luck. Link to comment
steadyfi Posted March 12, 2015 Author Share Posted March 12, 2015 db* functions are not slower in any way, so "speed" shouldn't be a problem. It's generally better that you create a private local database to the resources folder.Good luck. I wasn't saying the DB is slow, the events are lame and there is a slight delay in the GUIs + sometimes they need to be reopened. Anyway, thanks man. Link to comment
steadyfi Posted March 19, 2015 Author Share Posted March 19, 2015 Uhmm, sorry for bumping this topic up, but how do I get that ["rank"] and send it as a integer through a triggerClientEvent(target, "event", target, rank) where rank is the rank ? Link to comment
JR10 Posted March 19, 2015 Share Posted March 19, 2015 Depends on the variable that is assigned to the retval of dbPoll. local result = dbPoll(queryHandle, 0) local rank = result[1].rank -- Rank of the first row local rank = result[2].rank -- Rank of the second row rank = tonumber(rank) triggerClientEvent(target, "event", target, rank) Link to comment
steadyfi Posted March 19, 2015 Author Share Posted March 19, 2015 Depends on the variable that is assigned to the retval of dbPoll. local result = dbPoll(queryHandle, 0) local rank = result[1].rank -- Rank of the first row local rank = result[2].rank -- Rank of the second row rank = tonumber(rank) triggerClientEvent(target, "event", target, rank) Like this ? local result = executeSQLQuery("SELECT rank FROM otplayers WHERE player=? AND team=?", getAccountName(getPlayerAccount(player)), getTeamName(getPlayerTeam(player))) local rank = result[1].rank rank = tonumber(rank) triggerClientEvent(target, "event", target, rank) Im still using executeSQLQuery, too bored right now to change it Link to comment
JR10 Posted March 19, 2015 Share Posted March 19, 2015 Yes this should work. If you're only expecting one row, you can append 'LIMIT 1' to the query string, this can significantly improve performance as it will halt when it has found one row. Link to comment
steadyfi Posted March 19, 2015 Author Share Posted March 19, 2015 Yes this should work.If you're only expecting one row, you can append 'LIMIT 1' to the query string, this can significantly improve performance as it will halt when it has found one row. executeSQLQuery("SELECT rank FROM otplayers LIMIT 1 WHERE player=? AND team=?", getAccountName(getPlayerAccount(player)), getTeamName(getPlayerTeam(player))) Is it correct ? Link to comment
Tomas Posted March 19, 2015 Share Posted March 19, 2015 Yes this should work.If you're only expecting one row, you can append 'LIMIT 1' to the query string, this can significantly improve performance as it will halt when it has found one row. executeSQLQuery("SELECT rank FROM otplayers LIMIT 1 WHERE player=? AND team=?", getAccountName(getPlayerAccount(player)), getTeamName(getPlayerTeam(player))) Is it correct ? executeSQLQuery("SELECT rank FROM otplayers WHERE player=? AND team=? LIMIT 1;", getAccountName(getPlayerAccount(player)), getTeamName(getPlayerTeam(player))) Link to comment
steadyfi Posted March 20, 2015 Author Share Posted March 20, 2015 Ok, i ran into another problem. I tried some debugging, no problems in handlers or source element. I opened the SQL file, there were all the tables. The problem is in the SQL Function. addEvent("openteams.gui.playerOpensGUI", true) addEventHandler("openteams.gui.playerOpensGUI", getRootElement(), function() local team = getPlayerTeam(source) if team then --Player Rank local playerRank = executeSQLQuery("SELECT rank FROM otplayers WHERE player=? AND team=?", getAccountName(getPlayerAccount(source)), getTeamName(getPlayerTeam(source))) local rank = playerRank[1].rank local rank = tonumber(returnRank) outputChatBox("Rank "..tostring(rank)) --IGNORE, DEBUGGING --Leader Name local leaderName = executeSQLQuery("SELECT leader FROM otteams WHERE team=?", getTeamName(team)) local name = leaderName[1].name local name = tostring(returnName) outputChatBox("Leader "..tostring(name)) --IGNORE, DEBUGGING --Event triggerClientEvent(source, "openteams.gui.playerOpensGUI.return", source, returnRank, returnName) end end) The event get's triggered by a function Client Side, triggerServerEvent("openteams.gui.playerOpensGUI", localPlayer) And then it bounces back client side to open the GUI with the required information. Anyone ? Link to comment
JR10 Posted March 20, 2015 Share Posted March 20, 2015 local rank = tonumber(returnRank) returnRank is not defined, should be just 'rank', the same goes for returnName. Link to comment
TAPL Posted March 20, 2015 Share Posted March 20, 2015 At line 11 you selected leader and at line 12 you tried to get name but you haven't selected it. Link to comment
JR10 Posted March 20, 2015 Share Posted March 20, 2015 Apart from that, I would suggest you to use tables instead of querying the database each time you need the data. Also, you shouldn't be using source from client-side, read more about event faking here: triggerServerEvent Link to comment
steadyfi Posted March 20, 2015 Author Share Posted March 20, 2015 At line 11 you selected leader and at line 12 you tried to get name but you haven't selected it. local rank = tonumber(returnRank) returnRank is not defined, should be just 'rank', the same goes for returnName. Thank you guys, your posts helped me ! 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