Jump to content

Mysql question


stefutz101

Recommended Posts

function showmembers(playersource,command) 
    if not isGuestAccount(getPlayerAccount(playersource)) and getElementData(playersource,"gang") ~= "None" then 
        local members = getGangMembers(getElementData(playersource,"gang")) 
        outputChatBox(toJSON(members),playersource,255,255,255) 
    end 
end 
addCommandHandler("members",showmembers) 
  
getGangMembers = function(gangName) 
  if doesGangExists(gangName) then 
    local data = executeSQLQuery("SELECT member_account FROM gang_members WHERE gang_name = '" .. tostring(gangName) .. "'") 
    return data 
  else 
    return false, "The gang doesn't exists." 
  end 
end 

How i can make to display all members one per line . Because it displays something like this :

https://i.snag.gy/MKAqEo.jpg

{ [["member_account":"st3f101" ]]} I want to display only the account name.

Link to comment

I believe this is actually SQLlite, not mySQL. But there's no real difference regarding your question.

ON line 3 you output the result of the query using toJSON, toJSON is what makes it output in that way. In order to output it like you want you would have to use a loop.

  
for id,row in ipairs(members) do 
  outputChatBox(row.member_account) 
end 
  

More information about this can be found here https://www.lua.org/pil/7.3.html

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