MySQL return variable - 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 return variable (
/showthread.php?tid=495855)
MySQL return variable -
trukker1998 - 19.02.2014
Hello,
I want to get the variable from the field `id` in my MySQL database, this is used to give the players an own ID forever.
I need to get that ID from the database, but I don't know how

.
My pawncode:
Код:
public GetPlayersRealId(playerid)
{
new query[600], usersname[MAX_PLAYER_NAME+1];
GetPlayerName(playerid, usersname, sizeof(usersname));
format(query, sizeof(query), "SELECT * FROM playerdata WHERE user = '$s' LIMIT 1 ORDER BY id DESC", usersname);
mysql_query(query);
if(mysql_num_rows() == 1)
{
mysql_store_result(); new resultline[200];
if(mysql_fetch_row_format(resultline))
{
//Should return the ID.
}
mysql_free_result();
}
else
{
return 0;
}
return 1;
}
Screen of my table:
Help me pleas!
Re: MySQL return variable -
Misiur - 19.02.2014
Which MySQL plugin are you using?
Re: MySQL return variable -
Konstantinos - 19.02.2014
Remove the forward part of it.
pawn Код:
stock GetPlayersRealId(playerid)
{
new query[71], usersname[MAX_PLAYER_NAME], id;
GetPlayerName(playerid, usersname, sizeof(usersname));
format(query, sizeof(query), "SELECT id FROM playerdata WHERE user = '%s' LIMIT 1", usersname);
mysql_query(query);
mysql_store_result();
if(mysql_num_rows())
{
id = mysql_fetch_int();
mysql_free_result();
}
return id;
}
You had wrong in the syntax: '$s' instead of '%s'. The order by is not useful for that case. First store and then check the rows.
Re: MySQL return variable -
trukker1998 - 19.02.2014
Quote:
Originally Posted by Konstantinos
Remove the forward part of it.
pawn Код:
stock GetPlayersRealId(playerid) { new query[71], usersname[MAX_PLAYER_NAME], id; GetPlayerName(playerid, usersname, sizeof(usersname)); format(query, sizeof(query), "SELECT id FROM playerdata WHERE user = '%s' LIMIT 1", usersname); mysql_query(query); mysql_store_result(); if(mysql_num_rows()) { id = mysql_fetch_int(); mysql_free_result(); } return id; }
You had wrong in the syntax: '$s' instead of '%s'. The order by is not useful for that case. First store and then check the rows.
|
I will edit the post when I tried.
EDIT: It works, I will give u rep

.