SA-MP Forums Archive
Array size by MySQL rows number? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Array size by MySQL rows number? (/showthread.php?tid=547426)



Array size by MySQL rows number? - Stuneris - 22.11.2014

Hello, I have a question. How can I make array size by mysql_num_rows? I doing this:
Код:
LoadSomethingToArray(playerid)
{
        mysql_query("SELECT * FROM table");
	mysql_store_result();
	new array[MAX_PLAYERS][mysql_num_rows()];
        for(new i=0; i<mysql_num_rows(); i++)
       {
                format(query, sizeof(query), "SELECT * FROM table WHERE ID=%i", i);
		mysql_query(query);
		mysql_retrieve_row();
		mysql_fetch_field_row(fetch, "SomeCol");
		array[playerid][i] = fetch;
		mysql_free_result();
       }
}
But in this situation I can't use array in any code position. I want to load all info in player login and use in all code.
Loaded info is string.


Re: Array size by MySQL rows number? - Vince - 22.11.2014

Can't be done in Pawn. All array sizes must be known at compile time.


Re: Array size by MySQL rows number? - Stuneris - 22.11.2014

Quote:
Originally Posted by Vince
Посмотреть сообщение
Can't be done in Pawn. All array sizes must be known at compile time.
My code works properly, but I just can't use array in oter code locations.


Re : Array size by MySQL rows number? - Dutheil - 22.11.2014

Pawn language doesn't work like php...
Read this tutorial : https://sampforum.blast.hk/showthread.php?tid=485633


Re: Array size by MySQL rows number? - PowerPC603 - 22.11.2014

As Vince said, array size must be known at compile-time.
Creating the array inside the function would be pointless as well, because it will get deleted when you exit the function and taking the data with it.

Just make the array big enough to fit everything and put in outside functions.