Jump to content

MYSQL Database [Solved] Anyone Who Has MYSQL PROBLEM COME


3B00DG4MER

Recommended Posts

Hi Guys today i've make xampp localhost

i've make database,table.....

and yea,i tried to connect lua script with database and it's works

but i have a small problem

i tried to make a test : Selects all things in table and show them in a gridlist help plz

Here is Server:

  
connection = dbConnect( "mysql", "dbname=cir;host=localhost", "mtaserver", "game2020", "share=1" ) 
dbExec( connection, "INSERT INTO names VALUES (?,?)", 4, "test2" ) 
local allnames = dbExec( connection, "SELECT * FROM names") 
triggerClientEvent(getRootElement(),"onStart",allnames) 
  

Client:

  
    function testing( allnames ) 
    local playerList = guiCreateGridList ( 0.80, 0.10, 0.15, 0.60, true ) 
    local column = guiGridListAddColumn( playerList, "Player", 0.85 ) 
    for player in ipairs(allnames) do 
            local row = guiGridListAddRow ( playerList ) 
            guiGridListSetItemText ( playerList, row, column, getPlayerName ( player ), false, false ) 
        end 
  
end 
    addEvent("onStart",true) 
    addEventHandler("onStart",localPlayer,testing) 
  

Edited by Guest
Link to comment
You need to use dbQuery and dbPoll

i used them and it's tell me when i try to trigger: triggerClientEvent [Expected Element at Argument 3, got table]

i changed server:

function testsql() 
  
connection = dbConnect( "mysql", "dbname=cir;host=localhost", "mtaserver", "game2020", "share=1" ) 
dbExec( connection, "INSERT INTO names VALUES (?,?)", 4, "test2" ) 
local allnames = dbQuery( connection, "SELECT * FROM names") 
local result = dbPoll(allnames, -1) 
triggerClientEvent(getRootElement(),"onStart",result) 
end 
addCommandHandler("testmysql",testsql) 

Link to comment
Can you read? It clearly says that 3rd argument is supposed to be element, that is the base element (the source), just put root there... the table (result) is the 4th argument.

i fixed it

Now it's shows me

1

2

3

.....

i want to show the table things

ex:

in db table

1 Unknown

2 Gamer

3 Player

i want to show those in a gridlist

plz help

Link to comment
Can you read? It clearly says that 3rd argument is supposed to be element, that is the base element (the source), just put root there... the table (result) is the 4th argument.

i fixed it

Now it's shows me

1

2

3

.....

i want to show the table things

ex:

in db table

1 Unknown

2 Gamer

3 Player

i want to show those in a gridlist

plz help

Link to comment
function testsql(p) 
  
connection = dbConnect( "mysql", "dbname=cir;host=localhost", "mtaserver", "game2020", "share=1" ) 
dbExec( connection, "INSERT INTO names VALUES (?,?)", 4, "test2" ) 
local allnames = dbQuery( connection, "SELECT * FROM names") 
local result = dbPoll(allnames, -1) 
if #result ~= 0 then 
triggerClientEvent(p,"onStart",p,result) 
     end 
end 
addCommandHandler("testmysql",testsql) 
  

Link to comment
function testsql(p) 
  
connection = dbConnect( "mysql", "dbname=cir;host=localhost", "mtaserver", "game2020", "share=1" ) 
dbExec( connection, "INSERT INTO names VALUES (?,?)", 4, "test2" ) 
local allnames = dbQuery( connection, "SELECT * FROM names") 
local result = dbPoll(allnames, -1) 
if #result ~= 0 then 
triggerClientEvent(p,"onStart",p,result) 
     end 
end 
addCommandHandler("testmysql",testsql) 
  

There is Problem i told you i want to show rows as a Gridlist

yours show me Numbers in the gridlist

Anyone HELP ME !!! @_@

Link to comment
  
    function testing( allnames ) 
    local playerList = guiCreateGridList ( 0.80, 0.10, 0.15, 0.60, true ) 
    local column = guiGridListAddColumn( playerList, "Player", 0.85 ) 
    for k,v in pairs(allnames) do 
            local row = guiGridListAddRow ( playerList ) 
            guiGridListSetItemText ( playerList, row, column, v[1], false, false ) 
        end 
  
end 
    addEvent("onStart",true) 
    addEventHandler("onStart",localPlayer,testing) 
  

Link to comment
  
    function testing( allnames ) 
    local playerList = guiCreateGridList ( 0.80, 0.10, 0.15, 0.60, true ) 
    local column = guiGridListAddColumn( playerList, "Player", 0.85 ) 
    for k,v in pairs(allnames) do 
            local row = guiGridListAddRow ( playerList ) 
            guiGridListSetItemText ( playerList, row, column, v[1], false, false ) 
        end 
  
end 
    addEvent("onStart",true) 
    addEventHandler("onStart",localPlayer,testing) 
  

Near To Work

But there is Error

Client:

Line 7: Expected string at Argument 4,got Nil

Link to comment
dbExec( connection, "CREATE TABLE names (column1 TEXT, column2 TEXT)") 
dbExec( connection, "INSERT INTO names (column1, column2) VALUES (?,?)", 4, "test2" ) 

    function testing( allnames ) 
    local playerList = guiCreateGridList ( 0.80, 0.10, 0.15, 0.60, true ) 
    local column = guiGridListAddColumn( playerList, "Player", 0.85 ) 
    for k,v in pairs(allnames) do 
            local row = guiGridListAddRow ( playerList ) 
            guiGridListSetItemText ( playerList, row, column, v["column2"], false, false ) 
        end 
  
end 
addEvent("onStart",true) 
addEventHandler("onStart",localPlayer,testing) 

Link to comment
dbExec( connection, "CREATE TABLE names (column1 TEXT, column2 TEXT)") 
dbExec( connection, "INSERT INTO names (column1, column2) VALUES (?,?)", 4, "test2" ) 

    function testing( allnames ) 
    local playerList = guiCreateGridList ( 0.80, 0.10, 0.15, 0.60, true ) 
    local column = guiGridListAddColumn( playerList, "Player", 0.85 ) 
    for k,v in pairs(allnames) do 
            local row = guiGridListAddRow ( playerList ) 
            guiGridListSetItemText ( playerList, row, column, v["column2"], false, false ) 
        end 
  
end 
addEvent("onStart",true) 
addEventHandler("onStart",localPlayer,testing) 

Ty but i fixed before you talk

But anyone THANKS !!

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