Loading mysql table into samp array
#1

Hello, i have a question about how i can load from mysql table to samp array.
I want to load the mysql stuff like this:
Код:
new ALoads[][TLoad] =
{
        {"Gravel", false, 1.00, PCV_TruckerOreTrailer, {11}, {1, 2, 3}}, // LoadID 1
	{"Sand", false, 1.00, PCV_TruckerOreTrailer, {12}, {1, 2, 3, 4, 5}}, // LoadID 2
};
From this:
[img src="http://i.gyazo.com/8a818a61236d2a215fab6f0a34dfe296.png"][/img]

Does anyone know how to load that mysql table into an array in pawno?

Thank you in advance.
Reply
#2

MySQL array? Never heard of it.

What MySQL plugin of which version are you using? Syntax differs from version to version.
Reply
#3

Sorry for my fault in my post. I edited the post and im using Mysql R37
Reply
#4

Well this is one way:
pawn Код:
new Stuff[max][TLoad]; // Sorry for the non-mnemonic variable name but i have no idea what this code is for. Also change the "max" to an appropriate number.

public OnGameModeInit()
{
    mysql_pquery(connection_handler, "SELECT * FROM table_name","OnSomethingLoad","");
}
forward OnSomethingLoad();
public OnSomethingLoad()
{
   for(new i = 0; i < cache_get_row_count(); i++)
   {
        // Although the second dimension is an enum, i will be using indexes as you didn't give me that enum.
        cache_get_field_content(i, "Load",Stuff[i][0],connection_handler, size); // size must be changed to the variables size
        // I'm assuming that "Mafiaload" is a "String" type column
        cache_get_field_content(i, "Mafiaload", Stuff[i][1],
connection_handler,size);
        Stuff[i][2] = cache_get_field_content_float(i, "Payperunit");
        // For loading "vehicleneeded" column, look below.
        Stuff[i][3] = cache_get_field_content_int(i, "JobBlocs1");
        // For loading "Joblocs2" you should probably load it into a temporary string, then split it with sscanf and put it into your own array
   }
}
Loading "vehicleneeded" column: I can't write the code for it. You Pawn array seems to be using a define for it and MySQL table contains the name of the define. If that is true, it cannot be loaded because defines are not present in run-time.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)