HustraDev Posted February 6, 2016 Share Posted February 6, 2016 Hello guys, i have difficult in Inserting a row's from a custom database into a GUI grid list could any one help me i tried to make a trigger to export the rows from the custom db but my code doesn't work >>> client bindKey("F2", "down", function () if guiSetVisible ( wndPVList, false ) then guiSetVisible ( wndPVList, true ) triggerServerEvent("SelectRows", localPlayer) showCursor(true) else guiSetVisible ( wndPVList, false ) showCursor(false) end end ) server : addEvent("SelectRows",true) addEventHandler("SelectRows",getRootElement(), function() connect = dbConnect( "sqlite", "database.db" ) rows = dbExec(connect, "SELECT * FROM `VList` WHERE `account`=?",getAccountName(getPlayerAccount(source))) --- Client trigger .. to send [ rows ] and insert them into gridlist end ) Note : i want a way that i can insert this : - rows = dbExec(connect, "SELECT * FROM `VList` WHERE `account`=?",getAccountName(getPlayerAccount(source))) into a gridlist !!! Link to comment
Bonus Posted February 6, 2016 Share Posted February 6, 2016 1. if guiSetVisible ( wndPVList, false ) then Wtf? 2. Read the info! "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." 3. Don't like local? You should like it, use it! It's safer and faster. 4. Again, read the infos! dbExec: "This function executes a database query using the supplied connection. No result is returned." Don't use dbExec with select! 5. Use client instead of source. Else they can fake events and get the data of other players First of all fix these ones ... Link to comment
HustraDev Posted February 6, 2016 Author Share Posted February 6, 2016 server local connection = dbConnect( "sqlite", "database.db" ) addEvent("SelectRows",true) addEventHandler("SelectRows",getRootElement(), function() local rows = dbQuery( connection, "SELECT * FROM `VList` WHERE `account`=?",getAccountName(getPlayerAccount(client)) ) local result = dbPoll( rows, -1 ) end ) client bindKey("F2", "down", function () guiSetVisible ( wndPVList, false ) triggerServerEvent("SelectRows", localPlayer) showCursor(true) end ) Link to comment
Bonus Posted February 6, 2016 Share Posted February 6, 2016 Server is much better now, but client won't open that way. Serversided you should use triggerClientEvent to trigger the result, the best would be if you trigger result[1]. Clientsided you again need addEvent and addEventHandler. Here you use local gridlist = guiCreateGridList ( ... ) local columncolumn = guiGridListAddColumn ( gridlist, "Column", 0.2 ) local valuecolumn = guiGridListAddColumn ( gridlist, "Value", 0.8 ) for column, value in pairs ( triggeredresult ) do local row = guiGridListAddRow ( gridlist ) guiGridListSetItemText ( gridlist, row, columncolumn, column, false, false ) guiGridListSetItemText ( gridlist, row, valuecolumn, value, false, false ) end Wrote on phone Link to comment
HustraDev Posted February 6, 2016 Author Share Posted February 6, 2016 client ------------------- Gridlist ------------------ PlayerVehicleList = guiCreateGridList(9, 24, 407, 129, false, wndPVList) guiGridListAddColumn(PlayerVehicleList, "ID", 0.3) guiGridListAddColumn(PlayerVehicleList, "Name", 0.3) guiGridListAddColumn(PlayerVehicleList, "Price", 0.3) ------------------------------------------------ ------ Note : The same column we have in db table are exist in gridlist addEvent("SendRows",true) addEventHandler("SendRows",getRootElement(), function(result) for column, value in pairs ( result ) do local row = guiGridListAddRow ( PlayerVehicleList ) guiGridListSetItemText ( PlayerVehicleList, row, 1, value[1], false, false ) guiGridListSetItemText ( PlayerVehicleList, row, 2, value[2], false, false ) end end ) server addEvent("SelectRows",true) addEventHandler("SelectRows",getRootElement(), function() local rows = dbQuery( connection, "SELECT * FROM `VList` WHERE `account`=?",getAccountName(getPlayerAccount(client))) local result = dbPoll( rows, -1 ) triggerClientEvent(source,"SendRows",getRootElement(),result) end ) Link to comment
HustraDev Posted February 6, 2016 Author Share Posted February 6, 2016 i need help guy's .. Link to comment
Bonus Posted February 6, 2016 Share Posted February 6, 2016 And know you are doing other things again. 1. Why use source? Use client again! 2. Why use getRootElement() as source in triggerClientEvent? Use client again, its better. 3. When you trigger result instead of result[1] the array is in this form: result = { [1] = { [coulmn] = value, [column] = value ... }, [2] = ... ... [amountRowsInDatabase] = {...} } That means: To get the ID of the first vehicle you have to use result[1]["ID"] for index, row in pairs ( result ) do outputChatBox ( row["ID"]..": "..row["Name"] ) ... end And for your info: 0.3 + 0.3 + 0.3 = 0.9, not 1.0 Oh and next time WAIT ffs. It was fkin 6 AM here when you wrote this, maybe I am sleeping? 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