Jump to content

MYSQL Database [Solved] Anyone Who Has MYSQL PROBLEM COME


3B00DG4MER

Recommended Posts

Posted (edited)

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

SAF/SAO - 30%

Skype: Themerzoug2020

in-game name:3B00DG4MER

xOG7h1J.png

Posted
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) 

SAF/SAO - 30%

Skype: Themerzoug2020

in-game name:3B00DG4MER

xOG7h1J.png

Posted

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.

Lua Scripter

?ucet=miki_cz

Owner of mshost.cz MTA portal.

Posted
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

SAF/SAO - 30%

Skype: Themerzoug2020

in-game name:3B00DG4MER

xOG7h1J.png

Posted
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

SAF/SAO - 30%

Skype: Themerzoug2020

in-game name:3B00DG4MER

xOG7h1J.png

Posted
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) 
  

Posted
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 !!! @_@

SAF/SAO - 30%

Skype: Themerzoug2020

in-game name:3B00DG4MER

xOG7h1J.png

Posted
  
    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) 
  

Posted
  
    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

SAF/SAO - 30%

Skype: Themerzoug2020

in-game name:3B00DG4MER

xOG7h1J.png

Posted
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) 

Previously known as MrTasty.

Posted
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 !!

SAF/SAO - 30%

Skype: Themerzoug2020

in-game name:3B00DG4MER

xOG7h1J.png

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