bradio10 Posted January 21, 2015 Share Posted January 21, 2015 Hi, So I am working on an Inventory system and I am trying to get the item amount from an item and when I try to get it, it outputs this to the chat: table: 0x9b1c038 Not sure what this is, but it isn't what I want (I want the number that is under the amount) This is the sql command I am using: local currentAmount = exports.mysqlconfig:querySingle("SELECT itemAmount FROM `playerItems` WHERE `itemName` = ? AND `serial` = ?", name, serial) outputChatBox("" .. tostring(currentAmount)) I have tried querySingle and query and they both send the same thing. Link to comment
TAPL Posted January 21, 2015 Share Posted January 21, 2015 Try those: outputChatBox(tostring(currentAmount[1]["itemAmount"])) outputChatBox(tostring(currentAmount[1])) Link to comment
bradio10 Posted January 21, 2015 Author Share Posted January 21, 2015 Try those: outputChatBox(tostring(currentAmount[1]["itemAmount"])) outputChatBox(tostring(currentAmount[1])) First one gave an error: attempt to index field "?" (a nil value) Second one output nil Link to comment
TAPL Posted January 21, 2015 Share Posted January 21, 2015 Probably the table is empty. Link to comment
bradio10 Posted January 21, 2015 Author Share Posted January 21, 2015 Probably the table is empty. It can't be empty cus there is a data in it. I can see the data in phpMyAdmin. Link to comment
TAPL Posted January 21, 2015 Share Posted January 21, 2015 Maybe there was not match with the name and the serial which lead to zero result, therefore empty table. Link to comment
novo Posted January 21, 2015 Share Posted January 21, 2015 I'd rather try doing the following: for k,v in pairs(currentAmount) do outputChatBox(k.." => "..v) end as it might be possible that it's indexed this way: currentAmount["itemAmount"] instead as "querySingle" probably automatically adds "LIMIT 1" to your actual query (as the function's name contains single). Although, it would be way easier if you show us the mentioned function you're calling. 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