Jump to content

mysql reads all values equal to 2 from column


hotluapimp

Recommended Posts

it's working the way I hope there is no error, but I noticed that when checkingpedingQuery[1][status] == 2 it returns only 1 value from a row of the status column I can't make it read more columns with status 2 is only giving 1 line with status 2

function saqueBankMoney(thePlayer, money)
		local checkpedingQuery = dbPoll(dbQuery(sql, "SELECT * FROM dbt_withdraw WHERE user_id = ? AND status <> "..tonumber(5).."  ORDER BY status DESC ", getElementData(thePlayer, "char:userid")), -1)
		local amount =  string.format("%09.8f",checkpedingQuery[1]["amount"] or 0)
		local amount = tonumber(amount)
		local vip = getElementData(thePlayer, "char:vip") or 0
		local Moedas = string.format("%09.8f", getElementData(thePlayer, "char:vip")  or 0) 
		local balance =  Moedas - 0.00010000
	
		local man = 10000
if  checkpedingQuery[1]["status"] == 2 then

 	if money == getElementData(thePlayer, "char:vip") or money <= getElementData(thePlayer, "char:vip") then
		
		if  balance > amount then
	
        dbExec(sql, "UPDATE dbt_balance SET  balance = ? WHERE user_id = ?",balance, getElementData(thePlayer, "char:userid"))
        setElementData(thePlayer, "char:bankexchange", string.format("%09d", getElementData(thePlayer, "char:bankexchange")) + man)

        exports.logs:logMessage("[SAQUE]: "..getPlayerName(thePlayer).." ID: "..getElementData(thePlayer, "acc:id").." sacou R$: "..money.." no banco Total: "..getElementData(thePlayer, "char:vip").."", 1)	


        else
            exports.FR_DxMessages:addBox(thePlayer,"blocked funds", "error")
            exports.FR_DxMessages:addBox(thePlayer,"peding withdraw", "info")		
        end

else
	outputChatBox('#0071fe[TRANSFERIDOR] #FFFFFFVocê está sem dinheiro', thePlayer,255,255,255,true) 
end	

end
if checkpedingQuery[1]["status"] == 1 then 
       if money == getElementData(thePlayer, "char:vip") or money <= getElementData(thePlayer, "char:vip") then

          dbExec(sql, "UPDATE dbt_balance SET  balance = ? WHERE user_id = ?",balance, getElementData(thePlayer, "char:userid"))
          setElementData(thePlayer, "char:bankexchange",string.format("%09d", getElementData(thePlayer, "char:bankexchange")) + man)
      
      exports.FR_DxMessages:addBox(thePlayer,"Você retirou "..money.." do banco da exchange! ", "sucess")
      else
          outputChatBox('#0071fe[TRANSFERIDOR] #FFFFFFVocê está sem dinheiro', thePlayer,255,255,255,true) 
      end	

end
end

 

Link to comment
Quote

I noticed that when checkingpedingQuery[1][status] == 2 it returns only 1 value from a row of the status column I can't make it read more columns with status 2 is only giving 1 line with status 2

This is because you're explicitly checking if row 1's status column is equal to 2, rather than making this check per-row. If you want it per row, you need to iterate over each returned record like so

for i = 1, #checkpedingQuery do
  local row = checkpedingQuery[i]
  if row.status == 2 then -- or row["status"] (this is entirely equivalent, just different syntax, but the second one lets you plug a variable in there instead of a static string, the first version only works with static compile-time -- i.e. when the script loads -- strings)
    iprint(row)
  end
end
-- or
for index, row in pairs(checkpedingQuery) do
  if row.status == 2 then -- same remark as above
    iprint(row)
  end
end

 

Edited by Addlibs
Link to comment

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