jokerjab Posted April 10, 2014 Share Posted April 10, 2014 Hello guys, I'm having some problems with SQL. When I insert rows into columns and update it with new values so the old ones are replaced with the new ones, right? Ok so the second question is that how do I loop through the rows? It still keep giving me the same 100 value. function SQLTest() if executeSQLQuery("CREATE TABLE IF NOT EXISTS aa(Name TEXT, Cash NUMBER, Health NUMBER)") then if executeSQLQuery("INSERT INTO aa(Name, Cash, Health) VALUES(?,?,?)", "myName", 1554, 100 ) then -- 100 health local asa = 150 + getElementHealth(getPlayerFromName("What?")) -- should be 100 + now if executeSQLQuery("UPDATE aa SET Name = ?,Cash= ?,Health = ? WHERE Health = '"..asa.."'", "myName", 140, 100) then -- executed local Health = executeSQLQuery("SELECT * FROM aa WHERE Health = ?", 100) -- selected if #Health ~= 0 then outputChatBox ( Health[1]["Health"] ) -- but still the same 100 end end end end end SQLTest() This outputs 100? I think I'm updating it incorrectly any idea? Link to comment
TAPL Posted April 10, 2014 Share Posted April 10, 2014 Your code doesn't make much sense but anyway it should look something like: function SQLTest() if executeSQLQuery("CREATE TABLE IF NOT EXISTS aa(Name TEXT, Cash NUMBER, Health NUMBER)") then if executeSQLQuery("INSERT INTO aa(Name, Cash, Health) VALUES(?,?,?)", "myName", 1554, 100 ) then -- 100 health local asa = 150 + getElementHealth(getPlayerFromName("What?")) -- should be 100 + now if executeSQLQuery("UPDATE aa SET Name = ?,Cash= ?,Health = ? WHERE Health = 100", "myName", 140, asa) then -- executed local Health = executeSQLQuery("SELECT * FROM aa WHERE Health = ?", asa) -- selected if #Health ~= 0 then outputChatBox ( Health[1]["Health"] ) -- but still the same 100 end end end end end SQLTest() Link to comment
jokerjab Posted April 10, 2014 Author Share Posted April 10, 2014 Your code doesn't make much sense but anyway it should look something like: function SQLTest() if executeSQLQuery("CREATE TABLE IF NOT EXISTS aa(Name TEXT, Cash NUMBER, Health NUMBER)") then if executeSQLQuery("INSERT INTO aa(Name, Cash, Health) VALUES(?,?,?)", "myName", 1554, 100 ) then -- 100 health local asa = 150 + getElementHealth(getPlayerFromName("What?")) -- should be 100 + now if executeSQLQuery("UPDATE aa SET Name = ?,Cash= ?,Health = ? WHERE Health = 100", "myName", 140, asa) then -- executed local Health = executeSQLQuery("SELECT * FROM aa WHERE Health = ?", asa) -- selected if #Health ~= 0 then outputChatBox ( Health[1]["Health"] ) -- but still the same 100 end end end end end SQLTest() Thanks it works in this way. I was really going to do it in this way local Health = executeSQLQuery("SELECT * FROM aa WHERE Health = ?", asa) but after reading this tutorial kinda confused me but anyway I learned my lesson and next time I will go with wiki examples. Link to comment
TAPL Posted April 10, 2014 Share Posted April 10, 2014 You should check this website http://www.w3schools.com/sql/ Link to comment
Saml1er Posted April 10, 2014 Share Posted April 10, 2014 You should check this website http://www.w3schools.com/sql/ Wow thats something really useful. 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