GTX Posted July 16, 2012 Share Posted July 16, 2012 Hi. I researched wiki and I can't find same function for ryden's mysql. Is there any function in ryden's mysql which is similar to or same as dbPoll? Thanks in advance. Link to comment
Castillo Posted July 16, 2012 Share Posted July 16, 2012 I don't think dbPoll would be needed on Ryden's MySQL. Link to comment
Kenix Posted July 17, 2012 Share Posted July 17, 2012 wiki.multitheftauto.com/wiki/Modules/MTA-MySQL/mysql_fetch_assoc Link to comment
GTX Posted July 17, 2012 Author Share Posted July 17, 2012 Okay, nevermind for that. The code below returns this error: attempt to get length of a userdata value. Why? function updateRank() for i, v in ipairs(getElementsByType("player")) do if getElementData(v, "guest_") ~= 1 then local res = sqlC:query("SELECT * FROM accounts WHERE username='"..getElementData(v, "username_").."'") if res then local result = mysql_fetch_assoc(res) local rank = #sqlC:query("SELECT * FROM accounts WHERE points>='" .. result["points"].."'") if rank then setElementData(v, "Rank", rank) end end end end end Link to comment
Anderl Posted July 17, 2012 Share Posted July 17, 2012 Okay, nevermind for that.The code below returns this error: attempt to get length of a userdata value. Why? function updateRank() for i, v in ipairs(getElementsByType("player")) do if getElementData(v, "guest_") ~= 1 then local res = sqlC:query("SELECT * FROM accounts WHERE username='"..getElementData(v, "username_").."'") if res then local result = mysql_fetch_assoc(res) local rank = #sqlC:query("SELECT * FROM accounts WHERE points>='" .. result["points"].."'") if rank then setElementData(v, "Rank", rank) end end end end end "sqlC:query" is returning userdata, you can't get length of it. Use "mysql_fetch_assoc" and get length of it. Link to comment
GTX Posted July 17, 2012 Author Share Posted July 17, 2012 function updateRank() for i, v in ipairs(getElementsByType("player")) do if getElementData(v, "guest_") ~= 1 then local res = sqlC:query("SELECT * FROM accounts WHERE username='"..getElementData(v, "username_").."'") if res then local result = mysql_fetch_assoc(res) local rank = sqlC:query("SELECT * FROM accounts WHERE points>='" .. result["points"].."'") local r = #mysql_fetch_assoc(rank) if r then setElementData(v, "Rank", r) end end end end end That? It shows 0 for me. Link to comment
Anderl Posted July 17, 2012 Share Posted July 17, 2012 function updateRank() for i, v in ipairs(getElementsByType("player")) do if getElementData(v, "guest_") ~= 1 then local res = sqlC:query("SELECT * FROM accounts WHERE username='"..getElementData(v, "username_").."'") if res then local result = mysql_fetch_assoc(res) local rank = sqlC:query("SELECT * FROM accounts WHERE points>='" .. result["points"].."'") local r = #mysql_fetch_assoc(rank) if r then setElementData(v, "Rank", r) end end end end end That? It shows 0 for me. I don't know right cuz I don't use MySQL from much time but should not: "result["points"]" be "result[1].points" or "result[1]['points']"? Link to comment
GTX Posted July 17, 2012 Author Share Posted July 17, 2012 Then: attempt to index field '?' (a nil value) Link to comment
Cadu12 Posted July 17, 2012 Share Posted July 17, 2012 function updateRank() for i, v in ipairs(getElementsByType("player")) do if getElementData(v, "guest_") ~= 1 then local res = sqlC:query("SELECT * FROM accounts WHERE username='"..getElementData(v, "username_").."'") if res then local result = mysql_fetch_assoc(res) local rank = sqlC:query("SELECT * FROM accounts WHERE points>='" .. result["points"].."'") local r = mysql_fetch_assoc(rank) if r then setElementData(v, "Rank", r["points"]) end end end end end Link to comment
GTX Posted July 17, 2012 Author Share Posted July 17, 2012 function updateRank() for i, v in ipairs(getElementsByType("player")) do if getElementData(v, "guest_") ~= 1 then local res = sqlC:query("SELECT * FROM accounts WHERE username='"..getElementData(v, "username_").."'") if res then local result = mysql_fetch_assoc(res) local rank = sqlC:query("SELECT * FROM accounts WHERE points>='" .. result["points"].."'") local r = mysql_fetch_assoc(rank) if r then setElementData(v, "Rank", r["points"]) end end end end end This gets my points, and I want to make a "top list". Example: a = 100 points b = 101 points Element data: b = 1 a = 2 Link to comment
Cadu12 Posted July 17, 2012 Share Posted July 17, 2012 http://www.w3schools.com/sql/sql_orderby.asp Link to comment
GTX Posted July 17, 2012 Author Share Posted July 17, 2012 Okay, I got it. EDIT: Nevermind, it works now. Thank you Cadu! 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