itHyperoX Posted May 11, 2018 Share Posted May 11, 2018 (edited) Hi! I'm still learning mysql , and i started writing a vehicle system script. I stuck... I want to get that, is any vehicle already on that slot. How can i get that? I tried like 20 way, but just failed. I want something like this: I want to get is the player have vehicle on their Slot 1.. If yes, returning false. local result = (mysql:singleQuery("SELECT Slot=1 FROM vehicles WHERE VehicleOwnerAccountID=?", getElementData(source, "Player:AccountID"))) if tonumber(result) == 0 then local inserVehicle = mysql:execute("INSERT INTO vehicles (VehicleOwnerAccountID, Slot , VehicleID, Color, Plate, Spawned) VALUES (?, ?, ?, ?, ?, ?)", getElementData(source, "Player:AccountID"), 1, 411, 0, 0, 0) outputChatBox("ID:"..inserVehicle.VehicleDBID) mysql:singleQuery("UPDATE `accounts` SET `VehiclePerPlayerCount`=? WHERE `AccountID`=?", SlotQuery.VehiclePerPlayerCount + 1, getElementData(source, "Player:AccountID")) outputChatBox("Vehicle successfully inserted.", source) else outputChatBox("slot.") outputChatBox(tostring(result)) end Edited May 11, 2018 by TheMOG Link to comment
Addlibs Posted May 12, 2018 Share Posted May 12, 2018 (edited) local result = mysql:singleQuery("SELECT COUNT(*) as cnt FROM vehicles WHERE VehicleOwnerAccountID=? AND Slot=1", getElementData(source, "Player:AccountID")) local count = result.cnt or result[1].cnt -- depending on whether singleQuery returns a list of rows or the first row, but this code should work for both situations (?) if count >= 1 then -- slot occupied else -- slot free end Edited May 12, 2018 by MrTasty 1 Link to comment
itHyperoX Posted May 12, 2018 Author Share Posted May 12, 2018 5 hours ago, MrTasty said: local result = mysql:singleQuery("SELECT COUNT(*) as cnt FROM vehicles WHERE VehicleOwnerAccountID=? AND Slot=1", getElementData(source, "Player:AccountID")) local count = result.cnt or result[1].cnt -- depending on whether singleQuery returns a list of rows or the first row, but this code should work for both situations (?) if count >= 1 then -- slot occupied else -- slot free end Thank you. 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