24.11.2011, 15:37
Hello, ive started scripting mysql since yesterday and im trying to figure out how to use mysql_strtok to store names in 1 field.
This is my code
What i'm basically trying to do is store all player names that he has used with 1 ip. When he connects to server it will show the previous names he has used. I can't get it working, it overwrites the previous name, i want it to store the names like "name1|name2|name3" and when player connects he can see "Names: name1 name2 name3".
This is my code
Код:
public OnPlayerConnect(playerid) { if(!IsPlayerSaved(playerid)) { format(Query,sizeof(Query),"INSERT INTO `aka` (`ip`, `name`) VALUES ('%s', '%s')",IP, PName); mysql_query(Query); mysql_free_result(); } else { new query[200]; new ip[24]; new PName[MAX_PLAYER_NAME]; new templine[200], results[256], idx; GetPlayerIp(playerid, ip, sizeof(ip)); GetPlayerName(playerid, PName, sizeof PName); format(query, sizeof(query), "SELECT * FROM aka ORDER BY ip DESC"); mysql_query(query); mysql_store_result(); while(mysql_fetch_row_format(templine, "|")) { new info[256]; info = mysql_strtok(templine, idx, "|"); format(results, sizeof(results), "%s%s", results, PName); } mysql_free_result(); format(query, sizeof(query), "UPDATE aka SET name = '%s' WHERE ip = '%s'", results, ip); mysql_query(query); //mysql_store_result(); mysql_free_result(); format(results, sizeof(results), ""BLUE"Names: "GREEN"%s", results); SendClientMessageToAll(COLOR_BLUE, results); } return true; }
Код:
IsPlayerSaved(playerid) { new query[200]; new IP[16]; GetPlayerIp(playerid, IP, sizeof(IP)); format(query, sizeof(query), "SELECT * FROM aka WHERE ip = '%s'", IP); mysql_query(query); mysql_store_result(); if(mysql_num_rows() == 1) { //mysql_free_result(); return true; } else { //mysql_free_result(); return false; } }