Jump to content

MySQL query


bradio10

Recommended Posts

Posted

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.

Posted

Try those:

outputChatBox(tostring(currentAmount[1]["itemAmount"])) 

outputChatBox(tostring(currentAmount[1])) 

Posted
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

Posted

Maybe there was not match with the name and the serial which lead to zero result, therefore empty table.

Posted

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.

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...