Jump to content

[HELP] Recovering ID


BusDunk

Recommended Posts

Hello, I have an issue about recovering the ID. I wanted to create a bagback system with a line in the table foreach bag.

So I want to recover the ID of the bagback at the moment of its creation in the database.

This is my code :

  
local sql = dbQuery(handler,"SELECT * FROM bag") 
     local resultTable = dbPoll(sql, -1) 
          if resultTable then 
               for rowNum, rowData in ipairs(resultTable) do 
                    local bID = rowData['ID'] 
                    local newID = bID + 1 
                    dbExec(handler,"INSERT INTO bag (TYPE) VALUES ('1')") 
                    outputChatBox("ADD BAGBACK ID "..newID.."",source,125,0,0,true) 
  

This is the result of what I've done :

ChatBox :

ADD BAGBACK ID 2

ADD BAGBACK ID 3

ADD BAGBACK ID 4

ADD BAGBACK ID 5

ect ... about 10/20 new line

The script creates several lines with different ID instead of one line only

Thanks in advance for your help beacause it impedes me on the progress of my script.

PS : I'm a LUA beginner and I am learnig it by myself.

Link to post

Try this :

local sql = dbQuery(handler,"SELECT * FROM bag") 
     local resultTable = dbPoll(sql, -1) 
          if resultTable then 
               for rowNum, rowData in pairs(resultTable) do 
                    local bID = rowData['ID'] 
                    local newID = bID + 1 
                    dbExec(handler,"INSERT INTO bag (TYPE) VALUES ('1')") 
                    outputChatBox("ADD BAGBACK ID "..tonumber(newID).."",source,125,0,0,true) 

Link to post

Hi , i i have a problem like this but ,

i just want to know How i can recovering the ID of the MYSql Line i just create with my script.

Exemple :

I create an ATM in game. The script add a line in the MySQL DB , and i just want the script return me the number of the line was create. Thanks man.

Link to post

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...