MYSQL - Reading data from Database
#1

Hey everyone, having some problems reading data from my MYSQL database.

I have connected to the database fine etc. just having trouble reading from the database and assigning the value to a variable, string etc.

Код:
IsUserAdmin(playerid)
{
	new string[256],name[24],admin,line[256];
	GetPlayerName(playerid,name,24);
	format(string,sizeof(string),"SELECT * FROM dd_users WHERE nickname='%s'", name);
	samp_mysql_query(string);
	samp_mysql_store_result();
	samp_mysql_num_rows();
	while(samp_mysql_fetch_row(line))
	{
		samp_mysql_strtok(admin,"|",line);
	}
	if(admin==1)
	{
		return 1;
	} else {
		return 0;
	}
}
Reply
#2

That's not really clever.

Why don't you store the players variables into values once they login? Then you don't need to do such a huge amount of queries.
Reply
#3

I'm still learning the whole programming language, so I'm getting a little stumped...

With this, the player's information is saved in a database (nickname, password, ip, etc.)... Also whether or not they are an admin...

This: format(string,sizeof(string),"SELECT admin WHERE nickname='%s'",name); would give the result of either 1 for yes or 0 for no... But I just don't know how to get that value 1 or 0 out from the database and into a variable, string etc.

I've played around with a few of the MYSQL functions, but I'm stumped with this one...

And because of the way this script is written, its very important for me to be able to get this information out...

Thanks in advance for any advice...
Reply
#4

You cannot select something without defining the table you want it from.
It should be:
SELECT admin FROM table WHERE nickname='%s'.
Reply
#5

hehe Yeah my mistake with that... In my code it is "SELECT admin FROM dd_users WHERE nickname='%s'",name

Had a bit of a fail back there...

I just need to know how to get value is return into a string...

I understand in some situations you get multiple values, and in some situations I will need to know how to use those valuses, but with that specific query: "SELECT admin FROM dd_users WHERE nickname='%s'",name it will just return 1 or 0, I just don't know how to get that information into something I can use (string, float, int, etc.)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)