Getting value from SQL And storing it inside an array
#1

Hi, I'm trying to get a value from a row in the SQL, and then storing it into an array.
That's what I've done:
pawn Code:
format(query,sizeof(query),"SELECT `alevel` FROM `users` WHERE `username`='%s'",GN);
mysql_query(query),mysql_store_result();
mysql_fetch_field_row(plevel[playerid],"alevel"),mysql_free_result();
But it just doesn't work. Can you tell me what's the problem here?
Thanks !
Reply
#2

mysql_fetch_field_row stores the returned value in a string.

pawn Code:
format(query,sizeof(query),"SELECT `alevel` FROM `users` WHERE `username`='%s'", GN);
mysql_query(query);
mysql_store_result();
mysql_fetch_field_row(query, "alevel");
plevel[playerid] = strval(query);
mysql_free_result();
Reply
#3

I don't know which MySQL plugin you use, but to store it into an array, you have to use mysql_query_array
Reply
#4

Quote:
Originally Posted by Pinguinn
View Post
I don't know which MySQL plugin you use, but to store it into an array, you have to use mysql_query_array
You are not trying to use it on an array, your trying to use it on an array element. Which is the same as using it on a standard var. MP2 is right.

Because you are indexing the array plevel[ playerid ] you are storing it in the array.
Reply
#5

Quote:
Originally Posted by iggy1
View Post
You are not trying to use it on an array, your trying to use it on an array element. Which is the same as using it on a standard var. MP2 is right.

Because you are indexing the array plevel[ playerid ] you are storing it in the array.
Oh, I must've the misread title
Reply
#6

I've tried what MP2 said, but it isn't working :\
Reply
#7

I assume you're using BlueG's plugin, as that's the plugin which your MySQL Registration script in your signature uses. I also have no idea as to which version of the plugin you're using, so I am going to also assume you're using R7, the latest version.

If so, try using this:

pawn Code:
//This code where your other code was
format(query,sizeof(query),"SELECT `alevel` FROM `users` WHERE `username`='%s'",GN);
mysql_function_query(1,query,false,"OnAlevelResponse","i",playerid); //I hope you have playerid defined, because you must be getting GN from somewhere

//This needs to be declared somewhere else in the code
forward OnAlevelResponse(playerid);
public OnAlevelResponse(playerid)
{
    mysql_store_result();
    plevel[playerid] =  mysql_fetch_int();
    mysql_free_result();
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)