Hello guys,
I need help with this simple server script. Everything is working fine, the problem is that when I delete ID from the table. Take a look:
function onResourceStart()
executeSQLQuery("CREATE TABLE IF NOT EXISTS testing (id INT, text TEXT, name TEXT)")
end
addEventHandler("onResourceStart", resourceRoot, onResourceStart)
function onChat(msg, msgType)
if msgType == 0 then
theTable = executeSQLQuery("SELECT * FROM testing")
executeSQLQuery("INSERT INTO testing (id, text, name) VALUES (?,?,?)", #theTable + 1, msg, getPlayerName(source))
end
end
addEventHandler("onPlayerChat", root, onChat)
function showTable()
theTable = executeSQLQuery("SELECT * FROM testing")
for i,v in ipairs(theTable) do
outputChatBox("ID: "..tostring(v.id).." NAME: "..tostring(v.name).." MSG: "..tostring(v.text))
end
end
addCommandHandler("showtable", showTable)
function deleteFromTable(source, cmd, id)
executeSQLQuery("DELETE FROM testing WHERE id=?", id)
end
addCommandHandler("delete", deleteFromTable)
Suppose the table is:
ID: 1 NAME: Hamatora MSG: test
ID: 2 NAME: Hamatora MSG: test
ID: 3 NAME: Hamatora MSG: test
-> Use /delete 2
Means ID 2 will be deleted.
-> Now chat
-> Now use /showtable
You will see that ID 3 is repeated two times, thats the problem