26.06.2015, 12:20
(
Последний раз редактировалось AroseKhanNiazi; 26.06.2015 в 13:00.
)
thanks for the first part now second part
but it only printed
And yes that mysql log was my error some where else not nothing in log about this error too.
And the above code is note even updating the aka
EDIT fixed the above code had a small mistake
fixed version to help anyone else
and thanks for the help +rep
pawn Код:
forward OnAkaLoad(playerid); //forward
public OnAkaLoad(playerid) // public
{
new mysqlquery[124], //storing mysql format
name[MAX_PLAYER_NAME], // storing the name in row
ip[16], //storing the ip in row
namerow=-1, // will store where the name was found
iprow=-1; // will store where the ip was found
for(new i, j = cache_get_row_count(g_SQL); i < j; i++) // loop through all the rows that were found
{
cache_get_field_content(i, "username", name, g_SQL, MAX_PLAYER_NAME); // this will get the username from the current row
cache_get_field_content(i, "ip", ip, g_SQL, MAX_PLAYER_NAME); //this will get the ip from the current row
printf("Got row %d with name %s",i,name); // just for my own testing
if(strcmp(name,PlayerInfo[playerid][pUserName]) == 0) // the will match if the name from that field matches player name
{
printf("Name Matched in row %d with name %s",i,name); // just for my own testing
namerow=i; // will store player name row
}
if(strcmp(ip,PlayerInfo[playerid][pIP]) == 0) //this will match if the ip from player matches the one in row
{
printf("IP Matched in row %d with name %s",i,name); // just for my own testing
iprow=i; // will store player ip row
}
if(namerow == iprow) // this will check if the player name row and ip row are same
{
break; // as they are same no need to do anything further
}
}
if(namerow != -1) // will check if any row with that name was founded or not
{
mysql_format(g_SQL, mysqlquery, sizeof(mysqlquery), "INSERT INTO aka SET ip='%e',username='%e';",PlayerInfo[playerid][pIP],PlayerInfo[playerid][pUserName]);
print(mysqlquery);
mysql_pquery(g_SQL,mysqlquery); //no row with that name so inserting the aka
}
if(iprow != -1) //will check if any row with that ip was founded or not
{
mysql_format(g_SQL, mysqlquery, sizeof(mysqlquery), "INSERT INTO aka SET ip='%e',username='%e';",PlayerInfo[playerid][pIP],PlayerInfo[playerid][pUserName]);
print(mysqlquery);
mysql_pquery(g_SQL,mysqlquery); // no row with this ip inserting the aka
}
if(namerow != iprow) // will check if this ip was also stored for the name we are checking
{
mysql_format(g_SQL, mysqlquery, sizeof(mysqlquery), "INSERT INTO aka SET ip='%e',username='%e';",PlayerInfo[playerid][pIP],PlayerInfo[playerid][pUserName]);
print(mysqlquery);
mysql_pquery(g_SQL,mysqlquery); // updating the aka.
}
return 1;
Код:
SELECT ip,username FROM aka WHERE username = 'Sasuke_Uchiha' OR ip = '127.0.0.1'
And the above code is note even updating the aka
EDIT fixed the above code had a small mistake
pawn Код:
forward OnAkaLoad(playerid); //forward
public OnAkaLoad(playerid) // public
{
new mysqlquery[124], //storing mysql format
name[MAX_PLAYER_NAME], // storing the name in row
ip[16], //storing the ip in row
namerow=-1, // will store where the name was found
iprow=-1; // will store where the ip was found
for(new i, j = cache_get_row_count(g_SQL); i < j; i++) // loop through all the rows that were found
{
cache_get_field_content(i, "username", name, g_SQL, MAX_PLAYER_NAME); // this will get the username from the current row
cache_get_field_content(i, "ip", ip, g_SQL, MAX_PLAYER_NAME); //this will get the ip from the current row
printf("Got row %d with name %s",i,name); // just for my own testing
if(strcmp(name,PlayerInfo[playerid][pUserName]) == 0) // the will match if the name from that field matches player name
{
printf("Name Matched in row %d with name %s",i,name); // just for my own testing
namerow=i; // will store player name row
}
if(strcmp(ip,PlayerInfo[playerid][pIP]) == 0) //this will match if the ip from player matches the one in row
{
printf("IP Matched in row %d with name %s",i,name); // just for my own testing
iprow=i; // will store player ip row
}
if(namerow == iprow) // this will check if the player name row and ip row are same
{
break; // as they are same no need to do anything further
}
}
if(namerow == -1) // will check if any row with that name was founded or not
{
mysql_format(g_SQL, mysqlquery, sizeof(mysqlquery), "INSERT INTO aka SET ip='%e',username='%e';",PlayerInfo[playerid][pIP],PlayerInfo[playerid][pUserName]);
print(mysqlquery);
mysql_pquery(g_SQL,mysqlquery); //no row with that name so inserting the aka
}
else if(iprow == -1) //will check if any row with that ip was founded or not
{
mysql_format(g_SQL, mysqlquery, sizeof(mysqlquery), "INSERT INTO aka SET ip='%e',username='%e';",PlayerInfo[playerid][pIP],PlayerInfo[playerid][pUserName]);
print(mysqlquery);
mysql_pquery(g_SQL,mysqlquery); // no row with this ip inserting the aka
}
else if(namerow != iprow) // will check if this ip was also stored for the name we are checking
{
mysql_format(g_SQL, mysqlquery, sizeof(mysqlquery), "INSERT INTO aka SET ip='%e',username='%e';",PlayerInfo[playerid][pIP],PlayerInfo[playerid][pUserName]);
print(mysqlquery);
mysql_pquery(g_SQL,mysqlquery); // updating the aka.
}
return 1;
}
public OnQueryError(errorid, error[], callback[], query[], connectionHandle)
{
switch(errorid)
{
case CR_SERVER_GONE_ERROR:
{
printf("Lost connection to server, trying reconnect...");
mysql_reconnect(connectionHandle);
}
case ER_SYNTAX_ERROR:
{
printf("Something is wrong in your syntax, query: %s",query);
}
}
return 1;
}
and thanks for the help +rep