SQL Problem - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: SQL Problem (
/showthread.php?tid=658130)
SQL Problem -
ServerFiles - 24.08.2018
What is wrong this this code? everytime I search player name, it always returns can't find any even tho if I check the database, there is some players with same gpci.
PHP код:
COMMAND:omatch(playerid, params[])
{
if(!PlayerInfo[playerid][power]) return SendClientError(playerid, CANT_USE_CMD);
new emri[32];
if(sscanf(params, "s", emri)) return SCP(playerid, "<Player_Name>");
new sql[164], gpcija[64], Cache:result;
mysql_format(sqldb, sql, sizeof sql, "SELECT `PlayerInfo` FROM `gpci` WHERE `PlayerName` = '%s'", emri);
mysql_query(sqldb, sql);
cache_get_field_content(0, "gpci", gpcija);
mysql_format(sqldb, sql, sizeof sql, "SELECT * FROM `PlayerInfo` WHERE `gpci` = '%s'", gpcija);
result = mysql_query(sqldb, sql);
new rows = cache_num_rows();
if(rows)
{
new iStr[ 128 ];
for(new i; i < rows; i++)
{
new emri1[128];
cache_get_field_content(i, "PlayerName", emri1);
if(strcmp(emri1, emri))
{
format(iStr, sizeof(iStr), "{ea8080}[AC]:{f3c0c0} %s matches with %s", emri1, emri);
SendClientMessage(playerid, -1, iStr);
}
}
}
else
{
SendClientMessage(playerid, -1, "{ea8080}[AC]:{f3c0c0} Can't find any linked!");
}
cache_delete(result);
return 1;
}
Re: SQL Problem -
Nero_3D - 24.08.2018
You try to fetch the field
gpci although you only selected the column
PlayerInfo
Several other things
- Reduce the two queries to one with join
- If player names are unique, just select from PlayerInfo directly
- The strcmp line is wrong, currently it checks for "not equal"
- Use threaded queries if available
Re: SQL Problem -
ServerFiles - 24.08.2018
I make few changes, now it shows players name, but it shows randomly..
Like Player 1 have GPCI A12B and Player 2 have GPCI A13B and if I search for Player 1 GPCI it says it linked with Player 2 but it obvious both gpci is different.
Re: SQL Problem -
Nero_3D - 25.08.2018
You could print the player names to check manually but it is most probably a mistake in the if statement
Quote:
Originally Posted by Nero_3D
- The strcmp line is wrong, currently it checks for "not equal"
|
Re: SQL Problem -
ServerFiles - 25.08.2018
Alright thanks
Re: SQL Problem -
Sew_Sumi - 25.08.2018
There's also the thing that this is why gpci isn't really used as a sole indicator of whether someone is someone else.
It's known to produce duplicates, because of how it works, and it can be changed using mods.