xiti Posted May 4, 2012 Share Posted May 4, 2012 Hello everyone. I want help from someone with my load data function. I wanna wright a userpanel and without this i cant make this. I work on this some time and i cant solwe this problem, i try a lot of combination and i dont see a different in this code and idk why this dont work. Please help with this! here is my Load system: function loadPlayerData (thePlayer,datatype) if (thePlayer) and (datatype) then local guest = getElementData(thePlayer, "loggedin") if not (guest == false) then local account = getElementData(thePlayer, "account") local connect = dbConnect( "mysql", "dbname=localhost;host=localhost", "admin", "admin", "share=1" ) local findQuery = dbQuery( connect,"SELECT '"..datatype.."' FROM smf_sdmembers WHERE passwd='"..account.."'", datatype, account) if (findQuery) then outputChatBox(""..tostring(findQuery).."") local result, numrows, errmsg = dbPoll ( findQuery, -1 ) if numrows > 0 then outputChatBox(""..result.."") return result else return 0 end else outputDebugString("Failed to get "..datatype.." for player "..getPlayerName(thePlayer).." @ findQuery") end else outputDebugString("Player not logged "..getPlayerName(thePlayer)..".") end else outputDebugString("Bad arguments loadPlayerData.") end end Thank for help! Regards, Xiti Link to comment
xiti Posted May 4, 2012 Author Share Posted May 4, 2012 The script dont get from database any record what i want... I want a datatype - "cash" when i called this to the function then script cant return me this value. Someone help me? Link to comment
Michael# Posted May 4, 2012 Share Posted May 4, 2012 function loadPlayerData ( uPed, cData ) -- check if data have been passed if ( uPed and cData and type ( cData ) == 'string' ) then -- exists element data 'loggedin' ? if ( getElementData ( uPed, 'loggedin' ) ) then local cAccount = getElementData ( uPed, 'account' ) -- are u right that dbname is localhost? local vConnect = dbConnect ( 'mysql', 'dbname = localhost ; host = localhost', 'admin', 'admin', 'share = 1' ) local vQuery = dbQuery ( vConnect, 'SELECT `?` FROM smf_sdmembers WHERE passwd = `?`', cData, cAccount ) if ( vQuery ) then outputChatBox ( tostring ( vQuery ) ) local vResult, iRow, error = dbPoll ( vQuery, -1 ) if ( iRow > 0 ) then outputChatBox ( tostring ( vResult ) ) return vResult else return false end else outputDebugString ( 'Failed to get ' .. cData .. ' for player ' .. getPlayerName ( uPed ) .. ' @ ' .. error ) end else outputDebugString ( 'Player not logged in: ' .. getPlayerName ( uPed ) ) end else outputDebugString ( 'Bad argument @ loadPlayerData' ) end end Check comments. Link to comment
xiti Posted May 4, 2012 Author Share Posted May 4, 2012 Thanks Jayz but this not work now i dont know why, i try get a value from column exp and this still dont work. When i try get this the debugscript say me: dbPoll failed; Unknown column "exp" in "filed list". Someone help me? Thanks Here is a code which i try get this from database. loadPlayerData(thePlayer,"exp") Link to comment
Michael# Posted May 4, 2012 Share Posted May 4, 2012 Column exp not found. Check if column 'exp' is in database 'localhost'. Link to comment
xiti Posted May 4, 2012 Author Share Posted May 4, 2012 Yes column exp is in database... I know and idk why this dont work... Link to comment
xiti Posted May 4, 2012 Author Share Posted May 4, 2012 On 100% the column exp is in database... I check this again... Maybe problem is in '?' becouse when i try get this then call me that column '"exp"' not exsit not 'exp' becouse i have function with "" (loadPlayerData(thePlayer,"exp"). This is only sugestion. Link to comment
Castillo Posted May 5, 2012 Share Posted May 5, 2012 Note: Connecting and disconnecting many times can have a performance impact on the server. For optimal performance it is recommended that you use dbConnect only once when the resource starts, and share the connection element with the whole script. You should only connect when the resource starts, not every time you want to retrieve data. Try this: addEventHandler ( "onResourceStart", resourceRoot, function ( ) connect = dbConnect ( "mysql", "dbname=localhost;host=localhost", "admin", "admin", "share=1" ) end ) function loadPlayerData ( thePlayer, datatype ) if ( connect ) and ( thePlayer) and ( datatype ) then local guest = getElementData ( thePlayer, "loggedin" ) if ( not guest == false ) then local account = getElementData ( thePlayer, "account" ) local findQuery = dbQuery ( connect, "SELECT `".. datatype .."` FROM smf_sdmembers WHERE passwd = '".. account .."'" ) if ( findQuery ) then outputChatBox ( "".. tostring ( findQuery ).."" ) local result, numrows, errmsg = dbPoll ( findQuery, - 1 ) if ( numrows > 0 ) then outputChatBox ( "".. result [ 1 ] [ datatype ].."") return result [ 1 ] [ datatype ] else return 0 end else outputDebugString ( "Failed to get ".. datatype .." for player ".. getPlayerName ( thePlayer ) .." @ findQuery" ) end else outputDebugString ( "Player not logged ".. getPlayerName ( thePlayer ) .."." ) end else outputDebugString ( "Bad arguments loadPlayerData." ) end end Link to comment
xiti Posted May 5, 2012 Author Share Posted May 5, 2012 Oh my god this work! Solidsnake you are pro scripter, big beer for u! Thank so much. Thank's all what help me! 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