Jump to content

reading the MySQL column in lua


Recommended Posts

Hello friends,

I have created a column called "ok" in account, now I need to click on npc to check this example column:

column "ok" = 0

if the value of the "ok" column is 0 goes from the error message, if the value of the "ok" column is 1 of the correct message.

I hope you could understand.

Thank you for the attention.

 

        when info or button begin 
			say("blablabla")
			local f = select("bla si","bla no")
			if f == 1 then
				local c,query = mysql_direct_query("SELECT * FROM account.account WHERE id = '"..pc.get_account_id().."' LIMIT 1;")
				if query[1].ok < 1 then
					say'existe un valor menor a 1'
				else
					say'existe un valor de 1'
				end
			end
			if f == 2 then
			return
			end
        end 

 

not work =/

Link to comment
Share on other sites

  • Premium

If you created a new column called ok, you can just select that specific column instead of everything.

SELECT * FROM account.account

Will be

SELECT new_column FROM account.account

 

Here the example querying only the create_time:

imagem.png

Edited by Metin2 Dev
Core X - External 2 Internal
  • Love 1
Link to comment
Share on other sites

  • Premium
quest ok begin
	state start begin
		when info or button begin 
			say("blablabla")
			if (select("bla si", "bla no") == 1) then
				local _, query = mysql_direct_query(string.format("SELECT ok FROM account.account WHERE id = %d LIMIT 1;", pc.get_account_id()));
				
				say(string.format("value: %d;", query[1].ok))
			end -- if
		end -- when
	end -- state
end -- quest

 

make sure your 'ok' column only accepts "int" as value types.

  • Love 1

 

"Nothing's free in this life.

Ignorant people have an obligation to make up for their ignorance by paying those who help them.

Either you got the brains or cash, if you lack both you're useless."

Syreldar

Link to comment
Share on other sites

18 hours ago, Syreldar said:

quest ok begin
	state start begin
		when info or button begin 
			say("blablabla")
			if (select("bla si", "bla no") == 1) then
				local _, query = mysql_direct_query(string.format("SELECT ok FROM account.account WHERE id = %d LIMIT 1;", pc.get_account_id()));
				
				say(string.format("value: %d;", query[1].ok))
			end -- if
		end -- when
	end -- state
end -- quest

 

make sure your 'ok' column only accepts "int" as value types.

Thanks man :D

			if (select("bla si", "bla no") == 1) then
				local a_, query = mysql_direct_query(string.format("SELECT ok FROM account.account WHERE id = %d LIMIT 1;", pc.get_account_id()));
				if a_== id then
					say("ok")
				else
					say("no")
				end
				--say(string.format("value: %d;", query[1].ok))
			end -- if

 

one last question, how do I check 2 column in the same result?

 

Example:

 

			if (select("bla si", "bla no") == 1) then
				local a_, query = mysql_direct_query(string.format("SELECT ok,life FROM account.account WHERE id = %d LIMIT 1;", pc.get_account_id()));
				if a_== id then
					say("ok")
				else
					say("no")
				end
			end -- if

 

EDIT: Is not working =/

 

			if (select("bla si", "bla no") == 1) then
				local a_, query = mysql_direct_query(string.format("SELECT ok FROM account.account WHERE id = %d LIMIT 1;", pc.get_account_id()));
				if a_== id then
					say("ok")
				else
					say("no")
				end
				--say(string.format("value: %d;", query[1].ok))
			end -- if
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.