Jump to content

SQL _ GridList


Recommended Posts

No, You're using sql there's no need for xml .

is getPlayerName work

because I want name put in grid list thos name's in table

name = { 
  
"Alone", 
"BH", 
"KSA" 
  
} 
  
  
addEventHandler('onResourceStart',resourceRoot, 
  
    function () 
  
           local Tabel = executeSQLQuery("CREATE TABLE IF NOT EXISTS xAlhajarii ( name)") 
                         
            if ( Tabel ) then 
             
            outputDebugString( "Create Table xAlhajarii done") 
             
            local Results = executeSQLQuery("SELECT * FROM `xAlhajarii` WHERE PlayerName=?",name  ) 
             
            if ( Results == "table" and #Results == 0 or not Results  ) then 
             
             executeSQLQuery ( "INSERT INTO `xAlhajarii` ( PlayerName ) VALUES(?,?,?,?)",name) 
             
            else 
             
            executeSQLQuery('UPDATE `xAlhajarii` SET  PlayerName =?',name) 
             
           triggerClientEvent ("CallSQLPUT", getRootElement()) 
  
    end 
   end 
   end 
) 
  
  
Link to comment
You're getting the results on start :/ Bad idea when you show the gui you should get it also if you want to set a grid text use it client side i mean the table ( name ) .

so I wil put results in event PlayerJoin ?

and take it when player open the gui window with the bindkey

trigger to results ?

Link to comment
You're getting the results on start :/ Bad idea when you show the gui you should get it also if you want to set a grid text use it client side i mean the table ( name ) .

so I wil put results in event PlayerJoin ?

and take it when player open the gui window with the bindkey

trigger to results ?

Insert the results when a player press the button and get the results when a player show a gui .

Link to comment
You're getting the results on start :/ Bad idea when you show the gui you should get it also if you want to set a grid text use it client side i mean the table ( name ) .

so I wil put results in event PlayerJoin ?

and take it when player open the gui window with the bindkey

trigger to results ?

Insert the results when a player press the button and get the results when a player show a gui .

Server :

function Results() 
    local Results = executeSQLQuery("SELECT * FROM `xAlhajarii` WHERE PlayerName=?",getPlayerName ( name ) ) 
             
            if ( Results == "table" and #Results == 0 or not Results  ) then 
             
             executeSQLQuery ( "INSERT INTO `xAlhajarii` ( PlayerName ) VALUES(?,?,?,?)",getPlayerName(name)) 
             
            else 
             
            executeSQLQuery('UPDATE `xAlhajarii` SET  PlayerName =?',getPlayerName(name)) 
             
            end 
            end 
addEvent("gResults",true) 
addEventHandler("gResults",root,Results) 
------------------------------------------------------------------------------------------------------------------ 
addEvent("AreYouOpen?",true) 
addEventHandler("AreYouOpen?",root, 
function() 
Results() 
end 

Client :

  
  name = { 
  
"Alone", 
"BH", 
"KSA" 
  
} 
  
addEventHandler("onClientGUIClick",root, 
  function() 
   
  if ( source == vote) then 
   
  triggerServerEvent("gResults",gPlayer) --- i make it gPlayer for i made ( local gPlayer == getLocalPlayer() ) 
  
 end 
       end 
 ) 
--------------------------------------------------------- 
  
bindKey(Key,"down", 
  
function () 
    
   guiSetVisible( wnd , not guiGetVisible(wnd)) 
    
   showCursor(guiGetVisible(wnd)) 
              
    triggerServerEvent("AreYouOpen?",gPlayer) 
     
             end 
end 
     ) 

?

how I wil trigger table name from client to server ?

Link to comment

This is a simple on how to send/add to gridlist the content of a table:

-- client side:

addEventHandler ( "onClientResourceStart", resourceRoot, 
    function ( ) 
        myGridList = guiCreateGridList ( 50, 50, 100, 100, false ) -- Create a GUI gridlist 
        triggerServerEvent ( "getTableContent", localPlayer ) -- Trigger a server side event to get the data 
    end 
) 
  
addEvent ( "returnTableContent", true ) 
addEventHandler ( "returnTableContent", root, 
    function ( content ) 
        for _, text in ipairs ( content ) do -- Loop the items from the 'content' table sent from the server side. 
            guiGridListSetItemText ( myGridList, guiGridListAddRow ( myGridList ), 1, text, false, false ) -- Add it to the gridlist. 
        end 
    end 
) 

-- server side:

myTable = -- Define the table. 
    { 
        "Hello", 
        "World" 
    } 
  
addEvent ( "getTableContent", true ) 
addEventHandler ( "getTableContent", root, 
    function ( ) 
        triggerClientEvent ( client, "returnTableContent", client, myTable ) -- Send the 'myTable' content to the client side. 
    end 
) 

Link to comment
This is a simple on how to send/add to gridlist the content of a table:

-- client side:

addEventHandler ( "onClientResourceStart", resourceRoot, 
    function ( ) 
        myGridList = guiCreateGridList ( 50, 50, 100, 100, false ) -- Create a GUI gridlist 
        triggerServerEvent ( "getTableContent", localPlayer ) -- Trigger a server side event to get the data 
    end 
) 
  
addEvent ( "returnTableContent", true ) 
addEventHandler ( "returnTableContent", root, 
    function ( content ) 
        for _, text in ipairs ( content ) do -- Loop the items from the 'content' table sent from the server side. 
            guiGridListSetItemText ( myGridList, guiGridListAddRow ( myGridList ), 1, text, false, false ) -- Add it to the gridlist. 
        end 
    end 
) 

-- server side:

myTable = -- Define the table. 
    { 
        "Hello", 
        "World" 
    } 
  
addEvent ( "getTableContent", true ) 
addEventHandler ( "getTableContent", root, 
    function ( ) 
        triggerClientEvent ( client, "returnTableContent", client, myTable ) -- Send the 'myTable' content to the client side. 
    end 
) 

Client :

------------------------------------------------------- 
addEventHandler("onClientGUIClick",root, 
  function() 
   
  if ( source == vote) then 
   
  triggerServerEvent("gResults",gPlayer) --- i make it gPlayer for i made ( local gPlayer == getLocalPlayer() ) 
  
 end 
       end 
 ) 
--------------------------------------------------------- 
local Key = "F5" 
  
bindKey(Key,"down", 
  
function () 
    
   guiSetVisible( wnd , not guiGetVisible(wnd)) 
    
   showCursor(guiGetVisible(wnd)) 
              
    triggerServerEvent("AreYouOpen?",gPlayer) 
     
             end 
end 
     ) 
  
      
------------------------------------------------------------- 
  
  
  
addEvent ( "returnTableContent", true ) 
  
addEventHandler ( "returnTableContent", root, 
  
    function ( content ) 
  
        for _, text in ipairs ( content ) do -- Loop the items from the 'content' table sent from the server side. 
  
            guiGridListSetItemText ( GridList, guiGridListAddRow ( GridList ), 1, text, false, false ) -- Add it to the gridlist. 
  
        end 
  
    end 
) 
  

Server :

name = { 
  
"Alone", 
"BH", 
"KSA" 
  
} 
  
  
addEvent ( "getTableContent", true ) 
  
addEventHandler ( "getTableContent", root, 
  
    function ( ) 
  
        triggerClientEvent ( client, "returnTableContent", client, name ) -- Send the 'myTable' content to the client side. 
  
    end 
  
) 
  
local root = getRootElement() 
  
addEventHandler('onResourceStart',resourceRoot, 
  
    function () 
  
           local Tabel = executeSQLQuery("CREATE TABLE IF NOT EXISTS xAlhajarii ( name )") 
  
            if ( Tabel ) then 
             
            outputDebugString( "Create Table xAlhajarii done") 
    end 
   end 
   end 
) 
------------------------------------------------------------------------------------------------------------ 
  
function Results() 
    local Results = executeSQLQuery("SELECT * FROM `xAlhajarii` WHERE PlayerName=?",getPlayerName ( name ) ) 
             
            if ( Results == "table" and #Results == 0 or not Results  ) then 
             
             executeSQLQuery ( "INSERT INTO `xAlhajarii` ( PlayerName ) VALUES(?,?,?,?)",getPlayerName(name)) 
             
            else 
             
            executeSQLQuery('UPDATE `xAlhajarii` SET  PlayerName =?',getPlayerName(name)) 
             
            end 
            end 
addEvent("gResults",true) 
addEventHandler("gResults",root,Results) 
------------------------------------------------------------------------------------------------------------------ 
addEvent("AreYouOpen?",true) 
addEventHandler("AreYouOpen?",root, 
function() 
Results() 
end) 
  

?

Edited by Guest
Link to comment
Yes, you are using column names which doesn't exist.

Eg: "PlayerName", but your column is "name".

Also, you are inserting for 4 columns, but your table has just one.

but I need just 1 column

Never say i will not learn if you said that you're in the wrong section .

P.S : Good tut : https://forum.multitheftauto.com/viewtopic.php?f=148&t=38203.

bro in this example there is function for sql are canceled

I learn it but I can't to take column 1 just or I wil put like this ?

local Tabel = executeSQLQuery("CREATE TABLE IF NOT EXISTS xAlhajarii ( PlayerName ,? ,? )") 
Link to comment

Doesn't matter it's both .

addEventHandler('onResourceStart',getResourceRootElement ( getThisResource (    )   ), 
    function (      ) 
        executeSQLQuery ( 'CREATE TABLE IF NOT EXISTS `Like UnLike System` ( MyCoulmn[1],MyCoulmn[2],MyCoulmn[3] )' ) 
    end 
) 

You can add \ remove column .

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