Little help - MYSQL.
#1

I have this code.

Код:
GetNameFromSql(accId)
{
	new 
		query[STR_MAX],
		strid[32]
	;
	format(query, sizeof(query), "SELECT Name FROM players WHERE accid = '%d' LIMIT 1", accId);
	mysql_query(query);
	mysql_store_result();
	if(mysql_num_rows()==0)
	{
		format(strid, sizeof(strid), "None");
		return strid;
	}
	else
	{
		mysql_fetch_row(strid);
		new intid[32];
		strmid(intid, strid, 0, strlen(strid), 255);
		mysql_free_result();
		return intid;
	}
}
Now, this code will print my name as Test_User, but I want that it types Test User, without _
Please help!
Reply
#2

pawn Код:
stock NameUnder(playerid)
{
    new nu[MAX_PLAYER_NAME];
    GetPlayerName(playerid,nu,sizeof(nu));
    nu[strfind(nu,"_")] = ' ';
    return nu;
}
Reply
#3

That's not what I meant, check my first post.

With my previos code, it will print Test_User, but I want Test User.
Thanks for helping.
Reply
#4

Just put my code somewhere and call it inside your GetNameFromSql(accId) -.-
It will remove "_".
If you don't get what I mean:
pawn Код:
GetNameFromSql(accId)
{
    new query[STR_MAX],strid[32];
    format(query, sizeof(query), "SELECT Name FROM players WHERE accid = '%d' LIMIT 1",NameUnder(accId));
    mysql_query(query);
    mysql_store_result();
    if(mysql_num_rows()==0)
    {
        format(strid, sizeof(strid), "None");
        return strid;
    }
    else
    {
        mysql_fetch_row(strid);
        new intid[32];
        strmid(intid, strid, 0, strlen(strid), 255);
        mysql_free_result();
        return intid;
    }
}
Reply
#5

It doesn't work. It displays name: None
Reply
#6

pawn Код:
GetNameFromSql(accId)
{
    new
        query[STR_MAX],
        strid[32]
    ;
    format(query, sizeof(query), "SELECT Name FROM players WHERE accid = '%d' LIMIT 1", accId);
    mysql_query(query);
    mysql_store_result();
    if(mysql_num_rows()==0)
    {
        format(strid, sizeof(strid), "None");
        return strid;
    }
    else
    {
                new name[3][128];
        mysql_fetch_row(strid);
        mysql_free_result();
                split(strid, name, '_');
                format(strid, sizeof(strid), "%s %s", name[0], name[1]);
        return strid;
    }
}
try this....

and if you don't have split function here it is,

pawn Код:
stock split(const strsrc[], strdest[][], delimiter)
{
    new i, li;
    new aNum;
    new len;
    while(i <= strlen(strsrc))
    {
        if(strsrc[i] == delimiter || i == strlen(strsrc))
        {
            len = strmid(strdest[aNum], strsrc, li, i, 128);
            strdest[aNum][len] = 0;
            li = i+1;
            aNum++;
        }
        i++;
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)