31.05.2011, 14:57
Hi all,
I was wondering how to insert an array into a database. I believe you can't do that directly, or can you? In php you got this function, serialize, which converts an array into a string. With unserialize you can turn it back to an array. But this function is no native function in pawn so it's pretty useless.
I have been thinking about putting all the values of an array into floats and store them in the database. But that gives me more problems:
1. It takes a long time to perform;
2. It makes the database messy as well as the code.
I have also tried to store it as TEXT into the database. But then again you can't use Float:array[][]'s.
The real problem is that every 1500 miliseconds a script collects all the playerpositions (just the X's and Y's) and puts them in an array. Next those variables should be stored in the database. Third, a php script will take them from the database and put red markers on a map according to the coordinates of players. But I don't know what the best way is to store such an array in a database. Currently I got something like this
But that makes the server lagg because it takes too long.
If anybody has an idea of an efficient way to solve this I would like to hear about it.
Thanks in advance.
I was wondering how to insert an array into a database. I believe you can't do that directly, or can you? In php you got this function, serialize, which converts an array into a string. With unserialize you can turn it back to an array. But this function is no native function in pawn so it's pretty useless.
I have been thinking about putting all the values of an array into floats and store them in the database. But that gives me more problems:
1. It takes a long time to perform;
2. It makes the database messy as well as the code.
I have also tried to store it as TEXT into the database. But then again you can't use Float:array[][]'s.
The real problem is that every 1500 miliseconds a script collects all the playerpositions (just the X's and Y's) and puts them in an array. Next those variables should be stored in the database. Third, a php script will take them from the database and put red markers on a map according to the coordinates of players. But I don't know what the best way is to store such an array in a database. Currently I got something like this
Код:
new i, Query[1024]; for(i = 0; i < MAX_PLAYERS; i++){ format(Query, sizeof(Query), "UPDATE `samp`.`locations` SET `X` = '%f',`Y` = '%f' WHERE `locations`.`playerid` =%d;", positions[i][0], positions[i][1], i); mysql_query(Query); }
If anybody has an idea of an efficient way to solve this I would like to hear about it.
Thanks in advance.