Unkovic Posted August 25, 2018 Share Posted August 25, 2018 Im trying to create mysql players load, but i have this qh = dbQuery(DBConnection, "SELECT * FROM `players` WHERE `Name` = ? LIMIT 1", getPlayerName(source)) res = dbPoll(qh, -1) if(res) then triggerClientEvent(source, "prikazilog", source) for rid, row in ipairs (fromJSON(toJSON(res))) do for column, value in pairs (row) do setPlayerAnnounceValue(source, column, value) end end else triggerClientEvent(source, "prikazi", source) end end prikazilog is for showing login gui and prikazi is to show register gui so, where am i wrong. It shows login dialog everytime Link to comment
Dimos7 Posted August 25, 2018 Share Posted August 25, 2018 you need take username not player name but for the dialog idk Link to comment
Unkovic Posted August 25, 2018 Author Share Posted August 25, 2018 wtf it stores players name (game username) now i want to make loading, but it only works for those who have acc, im slighty updated code function joinHan() fadeCamera(source, true) showCursor(source, true) setPlayerHudComponentVisible (source, "clock", false ) qh = nil res = nil qh = dbQuery(DBConnection, "SELECT * FROM `players` WHERE `Name` = ? LIMIT 1", getPlayerName(source)) res = dbPoll(qh, -1) if(res) then for rid, row in ipairs (fromJSON(toJSON(res))) do if(rid == 0) then triggerClientEvent(source, "prikazi", source) elseif(rid > 0) then triggerClientEvent(source, "prikazilog", source) for column, value in pairs (row) do setPlayerAnnounceValue(source, column, value) end end end end end And again, it doesnt work for player who dont have acc (triggerClientEvent(source, "prikaz", source) Also I dont get any bug on /debugscript so? Link to comment
pa3ck Posted August 25, 2018 Share Posted August 25, 2018 1. dbPoll will always return true as long as the statement returned without an error, even though it's empty, which means your first if statement will always be true (unless DB error happens) 2. Since you are using LIMIT 1, there's no need to use loop, it's impossible to return multiple rows. 3. dbPoll returns a table with the following structure (only 1 row in your case): { { colname1=value1, colname2=value2, ... }, { colname1=value3, colname2=value4, ... }, ... } Try this: if res[1]["Name"] then outputChatBox("User is registered") else outputChatBox("User is not registered") end 4. fromJson(toJson(res)) - what are you trying to achieve there? Is your data saved as JSON object in DB? Either way, converting to then back from JSON is pointless. 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