Getting value from SQL And storing it inside an array -
Sphex - 01.05.2012
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

!
Re: Getting value from SQL And storing it inside an array -
MP2 - 01.05.2012
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();
Re: Getting value from SQL And storing it inside an array -
Pinguinn - 01.05.2012
I don't know which MySQL plugin you use, but to store it into an array, you have to use
mysql_query_array
Re: Getting value from SQL And storing it inside an array -
iggy1 - 01.05.2012
Quote:
Originally Posted by Pinguinn
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.
Re: Getting value from SQL And storing it inside an array -
Pinguinn - 01.05.2012
Quote:
Originally Posted by iggy1
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
Re: Getting value from SQL And storing it inside an array -
Sphex - 01.05.2012
I've tried what MP2 said, but it isn't working :\
Re: Getting value from SQL And storing it inside an array -
pyrodave - 04.05.2012
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;
}