SA-MP Forums Archive
Little help - MYSQL. - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Little help - MYSQL. (/showthread.php?tid=266062)



Little help - MYSQL. - NewbBeginner - 03.07.2011

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!


Re: Little help - MYSQL. - =WoR=Varth - 04.07.2011

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



Re: Little help - MYSQL. - NewbBeginner - 05.07.2011

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.


Re: Little help - MYSQL. - =WoR=Varth - 06.07.2011

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;
    }
}



Re: Little help - MYSQL. - NewbBeginner - 06.07.2011

It doesn't work. It displays name: None


Re: Little help - MYSQL. - CoaPsyFactor - 06.07.2011

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;
}