Gtagasje Posted November 11, 2013 Posted November 11, 2013 Hi there, I have a problem. I want to select all the rows of the mysql table, and then add 1 to that value. However, I don't know how to do this. I've tried around for an hour or so, just continiously trying different things, and I think this is the closest one I've come up with so far. (The connection works btw.) local atmidquery = dbQuery(connection, "SELECT COUNT(*) FROM atms") local atmidpoll = dbPoll(atmidquery, 500) if atmidpoll then atmid = tonumber(atmidpoll) + 1 else atmid = 0 end However, this doesn't work. It gives me the following error: attempt to perform arrithmic on nil value I am clueless on how to fix this, so maybe you guys can help me? Thanks in advance, Gtagasje. Yes, this is infact a signature.
Castillo Posted November 11, 2013 Posted November 11, 2013 local atmidquery = dbQuery ( connection, "SELECT COUNT(*) FROM atms" ) local atmidpoll = dbPoll ( atmidquery, 500 ) if ( atmidpoll ) then atmid = tonumber ( atmidpoll [ 1 ] [ "COUNT(*)" ] ) + 1 else atmid = 0 end Try it. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Gtagasje Posted November 11, 2013 Author Posted November 11, 2013 Works perfectly fine. Thanks again Castillo! Edit: I have another little problem with the same script. I want to load all the ATMs if I restart the server, but it only loads the first one in the table. This is my code for that: local qh = dbQuery(connection, "SELECT * FROM atms") local result = dbPoll(qh, 500) local atmcount = 0 if (result) then if type(result) == "table" then for i, v in ipairs(result) do And then it basicly converts the result to numbers so that I can add the atms and hitmarkers. But as I said, it only creates the first one in the table. Does anyone know how to fix this? Yes, this is infact a signature.
Gtagasje Posted November 12, 2013 Author Posted November 12, 2013 It still only loads the first one. EDIT: I might've found the problem, I think it creates them all at 1 place, since I get the gui 3 times when I hit the marker. Do you know how to fix this? if (result) then if type(result) == "table" then for i, v in ipairs(result) do local id = tonumber(result[1]["id"]) local x = tonumber(result[1]["x"]) local y = tonumber(result[1]["y"]) local z = tonumber(result[1]["z"]) local int = tonumber(result[1]["interior"]) local dim = tonumber(result[1]["dimension"]) local rot = tonumber(result[1]["rotation"]) Yes, this is infact a signature.
TAPL Posted November 12, 2013 Posted November 12, 2013 if (result) then if type(result) == "table" then for i, v in ipairs(result) do local id = tonumber(v["id"]) local x = tonumber(v["x"]) local y = tonumber(v["y"]) local z = tonumber(v["z"]) local int = tonumber(v["interior"]) local dim = tonumber(v["dimension"]) local rot = tonumber(v["rotation"])
Gtagasje Posted November 12, 2013 Author Posted November 12, 2013 Works perfect, thank you very much. Yes, this is infact a signature.
Castillo Posted November 12, 2013 Posted November 12, 2013 Works perfectly fine. Thanks again Castillo!Edit: I have another little problem with the same script. I want to load all the ATMs if I restart the server, but it only loads the first one in the table. This is my code for that: local qh = dbQuery(connection, "SELECT * FROM atms") local result = dbPoll(qh, 500) local atmcount = 0 if (result) then if type(result) == "table" then for i, v in ipairs(result) do And then it basicly converts the result to numbers so that I can add the atms and hitmarkers. But as I said, it only creates the first one in the table. Does anyone know how to fix this? You're welcome. San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
TAPL Posted November 12, 2013 Posted November 12, 2013 Works perfect, thank you very much. You're welcome.
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