MySQL 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: MySQL problem (
/showthread.php?tid=610784)
MySQL problem -
Edw - 28.06.2016
We have created a system and I have a little problem when extracting the name of the player database.
I do not know how well I understand but so idea:
PHP код:
mysql_format(SQL, szQuery, sizeof(szQuery), "SELECT * FROM `aplicatii`");
result = mysql_query(SQL, szQuery);
for(new i, j = cache_get_row_count (); i != j; ++i) {
cache_get_field_content(i, "Userid",szResult); userid = strval(szResult);
cache_get_field_content(i, "Date", szResult); format(date, 256, szResult);
printf("%d | %s", userid, date);
format(szDialog, sizeof(szDialog), "%s\t%s\n", GetNameFromDB(userid), date);
strcat(szDialog2, szDialog);
Selected[playerid][x] = userid;
x++;
}
cache_delete(result);
stock GetNameFromDB(userid) {
new szQuery[256], Cache: result;
mysql_format(SQL, szQuery, sizeof(szQuery), "SELECT * FROM `users` WHERE `id`='%d'", userid);
result = mysql_query(SQL, szQuery);
new szResult[256], szName[256];
format(szName, 256, "Null");
for(new i, j = cache_get_row_count (); i < j; i++)
{
cache_get_field_content(i, "username", szResult); format(szName, 256, szResult);
}
cache_delete(result);
printf("%s", szName);
return szName;
}
Debug:
PHP код:
With GetNameFromDB(userid):
[12:35:06] 1 | 1
[12:35:06] Null
[12:35:06] 1 | 1
[12:35:06] Null
[12:35:06] 1 | 1
[12:35:06] Null
[12:35:06] 1 | 1
Without:
[12:12:15] 1 | 1
[12:12:15] 2 | 2
[12:12:15] 3 | 3
[12:12:15] 4 | 4
Database:
I hope you understand.
Re: MySQL problem -
Edw - 28.06.2016
no one knows?
Re: MySQL problem -
SyS - 28.06.2016
what is exactly your problem?
Re: MySQL problem -
Edw - 28.06.2016
Quote:
Originally Posted by Sreyas
what is exactly your problem?
|
If using the 'GetNameFromDB' everywhere looks the same, view and debug (1, 1, 1, 1) if you do not use, looks correct database (1,2,3,4)
Re: MySQL problem -
Wantedboy21 - 28.06.2016
WHAT IS PROBLEM ?
Re: MySQL problem -
Konstantinos - 28.06.2016
Why don't you just join the two tables to get the player's name? Moreover consider using threaded queries:
pawn Код:
mysql_tquery(SQL, "SELECT a.Userid,IFNULL(u.username,\"\"),Date FROM aplicatii a LEFT JOIN users u ON u.id=a.Userid;", "OnAplicatiiLoadForPlayer", "i", playerid);
PHP код:
forward OnAplicatiiLoadForPlayer(playerid);
public OnAplicatiiLoadForPlayer(playerid)
{
new
tmp_userid,
tmp_date[32]; // change accordingly, 256 is way too much
szDialog2[0] = EOS; // reset the string, we don't want any text previously stored
for (new i, j = cache_get_row_count(); i != j; i++)
{
// rowid 0 = Userid | rowid 1 = username | rowid 2 = Date
tmp_userid = cache_get_row_int(i, 0);
cache_get_row(i, 1, szDialog);
cache_get_row(i, 2, tmp_date);
format(szDialog, sizeof szDialog, "%s\t%s\n", szDialog, tmp_date);
strcat(szDialog2, szDialog);
Selected[playerid][i] = tmp_userid;
}
}