MySQL return variable
#1

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!
Reply
#2

Which MySQL plugin are you using?
Reply
#3

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.
Reply
#4

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 .
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)