Jump to content

get data from server


nurfaizfy19

Recommended Posts

hello, sorry for my bad english

i want to get data from server side with database in client side

i have server side function:

function getPulsa(phone)
	local phoneSettings = mysql:query_fetch_assoc("SELECT * FROM `phones` WHERE `phonenumber`='"..mysql:escape_string(tostring(phone)).."' LIMIT 1")
	local pulsa = 0
	if not phoneSettings then
		outputChatBox("ERROR", source, 255, 0, 0)
	else
		pulsa = tonumber(phoneSettings["pulsa"]) or 0
	end
	return pulsa
end
addEvent("getPulsa", true)
addEventHandler("getPulsa", root, getPulsa)

and then i want to call the function in client side function:

function getPulsa(nomor)
	return triggerServerEvent("getPulsa", localPlayer, tonumber(nomor))
end

function testPulsa(commandName, nomoer)
	local pulsa = getPulsa(nomoer)
	outputChatBox(pulsa or "ERROR")
end
addCommandHandler("getpulsa", testPulsa, false, false)

when i try to execute the command "/getpulsa", the output is boolean. i need the output in number

thanks

Link to comment

you cant use

return pulsa

 

try with the code :)

--server:

   function getPulsa(phone)
        local phoneSettings = mysql:query_fetch_assoc("SELECT * FROM `phones` WHERE `phonenumber`='"..mysql:escape_string(tostring(phone)).."' LIMIT 1")
        local pulsa = 0
        if not phoneSettings then
            outputChatBox("ERROR", source, 255, 0, 0)
        else
            pulsa = tonumber(phoneSettings["pulsa"]) or 0
            triggerEvent ( "printData", root, pulsa )
        end
    end
    addEvent("getPulsa", true)
    addEventHandler("getPulsa", root, getPulsa)


--client:

    function getPulsa(nomor)
       triggerServerEvent("getPulsa", localPlayer, tonumber(nomor))
    end

    function testPulsa(commandName, nomoer)

    local pulsa = getPulsa(nomoer)
    end
    addCommandHandler("getpulsa", testPulsa, false, false)


function printData(data)
    outputChatBox(data)
end
addEvent("printData", true)
addEventHandler("printData", root,printData)

 

Edited by komal
Link to comment
  • Moderators
39 minutes ago, nurfaizfy19 said:

thanks for the advice but i need this, because i also use the function in server side. any idea?

thanks

 

You can use this enchantment, if you really NEED that:

 

Edited by IIYAMA
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...