how to: if the ip is different, upload into the database, if it is not different not upload to the database. i use mysql plugin BlueG R6.
|
Wow, I only learnt SQL like a few days ago and I understand him!
You need to query the database IP, check it against the player IP using "strcmp" (If you save them as strings, which I would expect as GetPlayerIp saves it in string form) If it doesn't match then update the database using the UPDATE query function. I trust you know how to retrieve data and update using MySQL already. |
new ip[20], pname[60], query[100];
GetPlayerIp(playerid, ip, sizeof(ip));
GetPlayerName(playerid, name, sizeof(name));
format(query, sizeof(query), "SELECT * FROM <table name> WHERE username = '%s' AND ip = '%s'", pname, ip);
mysql_query(query);
if(mysql_num_rows() == 1)
{
SendClientMessage(playerid, -1, "Your ip is the same!");
}
else {
new update[100];
format(update, sizeof(update), "UPDATE <table name> SET ip = '%s' WHERE username = '%s'", ip, pname);
SendClientMessage(playerid, -1, "Your ip is different!");
}
|
The 'true' is not needed there, neither is the '!'.
If you look at the strcmp documentation on the wiki, that param you have set true is the 'ignore case' param, since an IP is numbers and dots, this isn't needed. The exclamation means NOT when in front of a condition, strcmp returns false when a match is found and true otherwise, so you want to update the database if strcmp returns true: pawn Код:
tmpField would be the MySQL field returned from your query. Hope that helped ![]() |
new
tmpField[16], tmpIP[16];
mysql_fetch_field_row(tmpField, sizeof(tmpField));
GetPlayerIp(playerid, tmpIP, sizeof(tmpIP));
if(strcmp(tmpIP, tmpField))
{
format(query, sizeof(query), "UPDATE `%s` SET `Last_IP` = '%s' WHERE `Name` = '%s'", TABLE_NAME, ip(playerid), name(playerid));
mysql_query(query);
return 1;
}
|
Yes exactly! Although I'm not sure if this is faster than the other code posted by kikito.
And I'm sure the bump time is 48 hours, not 24 (I got told by an admin on one of my release threads!) |
|
And I'm sure the bump time is 48 hours, not 24 (I got told by an admin on one of my release threads!) |