Overkillz Posted December 17, 2016 Share Posted December 17, 2016 (edited) Hey there dear community, today I started to work on a system which will be sync with my forum, leaving out it. Im trying to update a value on a colum, however, I couldn't do it due to I cannot understand at all dbExec Function local tableAccount = {"plCash","plPoints","plMapsplayed","plMapswon","plWinratio","plHunters","plToptimes","plToptimes1","plPvps","plPvpswon","plPvpsratio"} function updatePlayerDatas(account) for i=1,#tableAccount do local randomValues = math.random(1,328842) dbExec (dbConnectTable.connection, "UPDATE core_members SET "..tableAccount[i].."="..randomValues.." WHERE `name` = "..account .."" ) end end Table: core_members Column: tableAccount Array Debugscript 3 drops me: You have an error on your SQL syntax ... Thanks for reading. Regards. Edited December 17, 2016 by Overkillz Link to comment
ViRuZGamiing Posted December 17, 2016 Share Posted December 17, 2016 (edited) I think (not sure) that it's better to run 1 query instead of multiple queries in a row dbExec (dbConnectTable.connection, "UPDATE core_members SET ?? = ??, ?? = ??, ?? = ??, ?? = ??, ?? = ??, ?? = ??, ?? = ??, ?? = ??, ?? = ??, ?? = ??, ?? = ?? WHERE `name` = ??", tableAccount[1], 0, tableAccount[2], 0, tableAccount[3], 0, tableAccount[4], 0, tableAccount[5], 0, tableAccount[6], 0, tableAccount[7], 0, tableAccount[8], 0, tableAccount[9], 0, tableAccount[10], 0, tableAccount[11], 0) Don't concat, use ?? and write the parameters in the end. It does seem a lot tho might be a better way and I haven't tested it Note that I've used 0 as value for everything this has to be changed Edited December 17, 2016 by ViRuZGamiing Link to comment
Overkillz Posted December 18, 2016 Author Share Posted December 18, 2016 Im a bit dump. I have solved the problem following ur example. I didn't realize that ??=?? expression is remplaced by the arguments. However, I was using a for, so, the code can be shorter by this local tableNamecall = "core_members" local name = "name" for i=1,#tableAccount do local randomValues = math.random(1000,328842) dbExec( dbConnectTable.connection, "UPDATE ?? SET ??=? WHERE ??=?", tableNamecall, tableAccount[i], randomValues, name, account ) end Regards. #You can close the topic Link to comment
ViRuZGamiing Posted December 18, 2016 Share Posted December 18, 2016 (edited) Your code is shorter indeed but the difference is, Analogue example: You're in a store and want 10 things, you: For each question do Look for a worker and ask where you Can find 1 thing. While you could ask all 10 items in 1 time. It's a performance difference Edited December 18, 2016 by ViRuZGamiing 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