fairyoggy Posted June 26, 2019 Share Posted June 26, 2019 Created a table called "123" with columns "login, "name" Created a table with dbQuery How can I make a chat message from the column "name" ? or just in label Smth like that outputToChat(" " ..getPlayerName(source).. " say: " ..message, v, 255, 100, 200, true) but instead getPlayerName(source) need information from the column (name) Link to comment
Moderators Patrick Posted June 26, 2019 Moderators Share Posted June 26, 2019 When the player logs in, save the 'name' variable to an elementData and use it. Link to comment
fairyoggy Posted June 26, 2019 Author Share Posted June 26, 2019 1 minute ago, stPatrick said: When the player logs in, save the 'name' variable to an elementData and use it. Earlier I used elementData only values in numbers. Can this be used in words? Link to comment
Moderators Patrick Posted June 26, 2019 Moderators Share Posted June 26, 2019 (edited) 4 minutes ago, slapz0r said: Earlier I used elementData only values in numbers. Can this be used in words? You can. function playerLogin(player) -- or smth like that (this is your login function) dbquery ... local mysql_result = dbPoll(...) local name_from_mysql = mysql_result[1].name setElementData(player, "name", name_from_mysql) end outputToChat(" " ..(getElementData(source,"name") or "Unknown").. " say: " ..message, v, 255, 100, 200, true) This is not the exact code, just a sketch. Edited June 26, 2019 by stPatrick 1 Link to comment
Moderators IIYAMA Posted June 26, 2019 Moderators Share Posted June 26, 2019 "SELECT `name` FROM `123` WHERE " .. accountName .. " = `login` LIMIT 1"; You want a @slapz0r, a query perhaps? Link to comment
fairyoggy Posted June 26, 2019 Author Share Posted June 26, 2019 21 minutes ago, IIYAMA said: "SELECT `name` FROM `123` WHERE " .. accountName .. " = `login` LIMIT 1"; You want a @slapz0r, a query perhaps? local accountName = getPlayerAccount(source) local qh = dbQuery(dbSecurityConnection, "SELECT `fname` FROM `accountsSecurity` WHERE " ..accountName.. " = `login` LIMIT 1" ) outputChatBox( 'Ваш ник: '..qh, source, 255, 0, 0, true ) fname = name accountsSecurity = 123 What am I doing wrong? Link to comment
fairyoggy Posted June 26, 2019 Author Share Posted June 26, 2019 connection = dbConnect("sqlite", "accs.db") queryhandle = dbQuery( connection, 'SELECT * FROM accountsSecurity') result = dbPoll(queryhandle, -1) for rid, row in ipairs (result) do -- row represents the tables that are in 'result', which represent the rows for column, value in pairs (row) do -- column represents column name, value represents column value outputChatBox(column..', '..value) end end I need it to work like this, just need to select a specific column, and not the whole table. Link to comment
fairyoggy Posted June 26, 2019 Author Share Posted June 26, 2019 local dbSecurityConnection = dbConnect( 'sqlite', 'accs.db') local getAnswerData = dbQuery( dbSecurityConnection, ' SELECT `fname` FROM `accountsSecurity` WHERE Login = ? ', getAccountName(getPlayerAccount(source)) ) local checkAnswerValue = dbPoll( getAnswerData, -1 ) local getAnswerData2 = dbQuery( dbSecurityConnection, ' SELECT `sname` FROM `accountsSecurity` WHERE Login = ? ', getAccountName(getPlayerAccount(source)) ) local checkAnswerValue2 = dbPoll( getAnswerData2, -1 ) for rid, row in ipairs (checkAnswerValue2) do -- row represents the tables that are in 'result', which represent the rows for column, value in pairs (row) do -- column represents column name, value represents column value outputChatBox(column..'_'..value) end end Did this way. In the chat, the column name is displayed and it contains . How to make the chat displayed 2 columns at once? outputChatBox(column..'_'..value) Instead column.. need getAnswerData(fname) How it's correctly ? Link to comment
Hugos Posted June 26, 2019 Share Posted June 26, 2019 4 hours ago, slapz0r said: Created a table called "123" with columns "login, "name" Created a table with dbQuery How can I make a chat message from the column "name" ? or just in label Smth like that outputToChat(" " ..getPlayerName(source).. " say: " ..message, v, 255, 100, 200, true) but instead getPlayerName(source) need information from the column (name) Do you need to get a name from the table? Link to comment
fairyoggy Posted June 26, 2019 Author Share Posted June 26, 2019 2 minutes ago, Hugos said: Do you need to get a name from the table? Yes from .db Link to comment
Hugos Posted June 26, 2019 Share Posted June 26, 2019 (edited) addEvent("CheckName", true) function OnPlayerCheck(name) qh_name = dbQuery(db, "SELECT * FROM dbQuery WHERE name=?", rname) --Find the row in the table local result = dbPoll(qh_name, -1) if #result >= 1 then --if the result is correct outputToChat(" " ..result.. " say: " ..message, v, 255, 100, 200, true) else --endIf the "name" is incorrect end addEventHandler("CheckName", root, CheckName) Server text = guiCreateEdit(0, 0, 0, 0, "", false) function btn(button) --function if the player pressed the button. if button == "left" then local CheckName = guiGetText(text) --Get the name - from the edit field (guiCreateEdit) triggerServerEvent("CheckName", getLocalPlayer(), name) --Server end end Client In this example, I get the name of the player that he enters in "guiCreateEdit" >> Find it in the database >> If found, output the text Edited June 26, 2019 by Hugos Link to comment
fairyoggy Posted June 26, 2019 Author Share Posted June 26, 2019 local dbSecurityConnection = dbConnect( 'sqlite', 'accs.db') local getAnswerData = dbQuery( dbSecurityConnection, ' SELECT `fname`,`sname` FROM `accountsSecurity` WHERE Login = ? ', getAccountName(getPlayerAccount(source)) ) local result = dbPoll( getAnswerData, -1 ) if result then for rid, row in ipairs ( result) do for column, value in pairs ( row ) do end local fname = row["fname"] local sname = row["sname"] outputChatBox (fname..'_'..sname, source, 0, 255, 0, true ) end end end How do I use this on the client side? I mean, for example, I have a label on a client And how to make "fname" from server side to client in this label? smth like that guiSetText ( myLabel, fname ) 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