Jump to content
  • 0

Select table value function


DaNy3LL

Question

Hello guys, I wrote a function to select the value from a table field (has default value set to 0)

 

ced7fce503bd3f6c3c17595546d0fef6.png

function check_security()
	local a = mysql_query("SELECT * FROM account.account WHERE id = "..pc.get_player_id().."")
	return a.security_status[1]
end

the function gives this error in syserr

attempt to index field `security_status' (a nil value)

and this kinda works, but it's not getting the default value of the field (0) - it shows else even if the value in the field is 0

function check_security()
	local a = mysql_query("SELECT * FROM account.account WHERE id = "..pc.get_player_id().."")
	return security_status
end
if check_security() == 0 then
	say("VALUE 0")
else 
	say("OTHER VALUE")
end

Kind Regards, DaNy3LL

Link to comment

5 answers to this question

Recommended Posts

  • 0
  • VIP
int query_select(lua_State* L)
	{
		SQLMsg * pMsg = DBManager::instance().DirectQuery(lua_tostring(L, 1));
		if (pMsg != NULL)
		{
			if (pMsg->Get()->uiNumRows == 0)
			{
				M2_DELETE(pMsg);
				return 0;
			}

			MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
			long long wynik_query = 0;
			str_to_number(wynik_query, row[0]);

			M2_DELETE(pMsg);

			lua_pushnumber(L, wynik_query);

			return 1;
		}
		return 0;
	}

return query_select("select security_code from account.account where id = "..pc.get_account_id()..";")

  • Love 2
Link to comment
  • 0

Thanks , it works now

 

But how can I set "security_status" field value to 1

function set_as_status(status)
	local a = mysql_query("UPDATE account.account SET security_status = "..status.." WHERE id = "..pc.get_player_id().."")
end

This doesn't update the value

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


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