How could I ? [mysql]
#1

Hi everybody,


I've an unban cmd and I want to know how could I return something if the Username doesn't exist in the database ?
Thank you !

My unban CMD:
Код:
CMD:aunban(playerid, params[])
{
    if(pInfo[playerid][Admin] < 70)
        return SendClientMessage(playerid, Rouge,"La commande entrйe est inconnue !");       
    new nom[24], query[128];
    if(sscanf(params,"s[24]", nom)) return SendClientMessage(playerid, Gris, "/aunban [Nom_Prйnom du joueur]");
    format(query, sizeof(query), "SELECT * FROM `joueurs` WHERE `Bannis` = '1' AND `Username` = '%s' LIMIT 1", nom);
    mysql_tquery(mysql, query, "OnEssaiUnban","is", playerid, nom);
    return 1;
}
OnEssaiUnban:
Код:
public OnEssaiUnban(playerid, nom[])
{
    new string[128], query[128];
    if(!cache_get_row_count())
    {
        SendClientMessage(playerid, Rouge, "Ce joueur n'est pas bannis !");
        return 1;
    }

    mysql_format(mysql, query, sizeof(query),"UPDATE `joueurs` SET `Bannis` = '0', `RaisonBan`='' WHERE `Username` = '%e'", nom);
    mysql_tquery(mysql, query, "","");
    GetPlayerName(playerid, joueuremetteur, sizeof(joueuremetteur));
    format(string, sizeof(string), "[Admin]:%s a unban %s.", joueuremetteur, nom);
    ChannelAdmin(Rouge, string);
    return 1;
}
Reply
#2

Bump
Reply
#3

Before you ban try this(Simple Way):
Quote:

SELECT Username FROM 'your_table' WHERE Username='PLAYERNAME'

Then use mysql_num_rows to get if any row exists.
If it returns 0 then the user doesn't exist.

Or check after you send the BAN query.If it returns a value then the player has been banned or else nothing happens to the database and you'll come to know that user doesn't exist.This method eliminates an additional query.
Reply
#4

I don't understand why are u speaking about ban someone^^
I just want to return something if a Username doesn't exist in the database. I did this. Now it work.


But even if the player is not banned, it say that he has been unbanned.


Код:
public OnEssaiUnban(playerid, nom[])
{
    new string[128], query[128];
    if(!cache_get_row_count())
    {
        SendClientMessage(playerid, Rouge, "Ce joueur n'existe pas !");
        return 1;
    }

	mysql_format(mysql, query, sizeof(query), "SELECT * FROM `joueurs` WHERE `Bannis`='1' AND `Username`='%s' LIMIT 1", nom);
	mysql_tquery(mysql, query, "", "");
	if(!cache_get_row_count()) // This part doesn't work. It should return that the player isnt banned when I try to unban someone who isn't banned.
    {
        SendClientMessage(playerid, Rouge, "Ce joueur n'est pas bannis !");
        return 1;
    }
    mysql_format(mysql, query, sizeof(query),"UPDATE `joueurs` SET `Bannis` = '0', `RaisonBan`='' WHERE `Username` = '%e'", nom);
    mysql_tquery(mysql, query, "", "");
    GetPlayerName(playerid, joueuremetteur, sizeof(joueuremetteur));
    format(string, sizeof(string), "[Admin]:%s a unban %s.", joueuremetteur, nom);
    ChannelAdmin(Rouge, string);
    return 1;
}
Код:
CMD:aunban(playerid, params[])
{
    if(pInfo[playerid][Admin] >= 70)
	{
		new nom[24], query[128];
		if(sscanf(params,"s[24]", nom)) return SendClientMessage(playerid, Gris, "/aunban [Nom_Prйnom du joueur]");
		format(query, sizeof(query), "SELECT * FROM `joueurs` WHERE `Username` = '%s' LIMIT 1", nom);
		
		mysql_tquery(mysql, query, "OnEssaiUnban","is", playerid, nom);
		return 1;
	}
	return SendClientMessage(playerid, Rouge,"La commande entrйe est inconnue !");
}
Reply
#5

Код:
	if(!mysql_num_rows()) {//this basically means if(false mysql_num_rows bla bla bla...

		SendClientMessage(playerid, ADMIN_ACTION, "•• This is a non-existing ban Playerid.");
	}
Reply
#6

Thank you,

so this should work ?:

Код:
public OnEssaiUnban(playerid, nom[])
{
    new string[128], query[128];
    if(!cache_get_row_count())
    {
        SendClientMessage(playerid, Rouge, "Ce joueur n'existe pas !");
        return 1;
    }

	mysql_format(mysql, query, sizeof(query), "SELECT * FROM `joueurs` WHERE `Bannis`='1' AND `Username`='%s' LIMIT 1", nom);
	mysql_tquery(mysql, query, "", "");
	if(!mysql_num_rows())
    {
        SendClientMessage(playerid, Rouge, "Ce joueur n'est pas bannis !");
        return 1;
    }
    mysql_format(mysql, query, sizeof(query),"UPDATE `joueurs` SET `Bannis` = '0', `RaisonBan`='' WHERE `Username` = '%e'", nom);
    mysql_tquery(mysql, query, "", "");
    GetPlayerName(playerid, joueuremetteur, sizeof(joueuremetteur));
    format(string, sizeof(string), "[Admin]:%s a unban %s.", joueuremetteur, nom);
    ChannelAdmin(Rouge, string);
    return 1;
}
Cause it doesn't work for me.
When I unban a player the Banned value is set to 0, if the player is banned to 1.
What I want to do is, if Banned is set to 0, return "This player isn't banned".

But it doesn't work, I don't know why.


Thank you.
Reply
#7

Well then the cmd won't matter you need it to detect that OnPlayerConnect or whatever system you use. The cmd works fine it sets the banis to 0 You just need it to detect...
Reply
#8

Thank you !

I did this now it works:

Код:
public OnEssaiUnban(playerid, nom[])
{
    new string[128], query[128];
    if(!cache_get_row_count())
    {
        SendClientMessage(playerid, Rouge, "Ce joueur n'existe pas !");
        return 1;
    }

	mysql_format(mysql, query, sizeof(query), "SELECT * FROM `joueurs` WHERE `Bannis`='1' AND `Username`='%s' LIMIT 1", nom);
	mysql_tquery(mysql, query, "", "");
	if((cache_get_row_int(0, 17)) != 1)
    {
        SendClientMessage(playerid, Rouge, "Ce joueur n'est pas bannis !");
        return 1;
    }
    mysql_format(mysql, query, sizeof(query),"UPDATE `joueurs` SET `Bannis` = '0', `RaisonBan`='' WHERE `Username` = '%e'", nom);
    mysql_tquery(mysql, query, "", "");
    GetPlayerName(playerid, joueuremetteur, sizeof(joueuremetteur));
    format(string, sizeof(string), "[Admin]:%s a unban %s.", joueuremetteur, nom);
    ChannelAdmin(Rouge, string);
    return 1;
}
But is it possible to optimize it ?


Thank you !
Reply
#9

pawn Код:
public OnEssaiUnban(playerid, nom[]) {
    new string[128], query[128];
    if(!cache_get_row_count()) {
        SendClientMessage(playerid, Rouge, "Ce joueur n'existe pas !");
        return 1; }

    mysql_format(mysql, query, sizeof(query), "SELECT * FROM `joueurs` WHERE `Bannis`='1' AND `Username`='%s' LIMIT 1", nom);
    mysql_tquery(mysql, query, "", "");
    if((cache_get_row_int(0, 17)) != 1) {
        SendClientMessage(playerid, Rouge, "Ce joueur n'est pas bannis !");
        return 1; }
       
    mysql_format(mysql, query, sizeof(query),"UPDATE `joueurs` SET `Bannis` = '0', `RaisonBan`='' WHERE `Username` = '%e'", nom);
    mysql_tquery(mysql, query, "", "");
    GetPlayerName(playerid, joueuremetteur, sizeof(joueuremetteur));
    format(string, sizeof(string), "[Admin]:%s a unban %s.", joueuremetteur, nom);
    ChannelAdmin(Rouge, string);
    return 1;
}
that's the most you can optimize it... You welcome
Reply
#10

The code you had returned a message if there were no rows so you asked for something your code already does.
Quote:
Originally Posted by SwisherSweet
Посмотреть сообщение
pawn Код:
public OnEssaiUnban(playerid, nom[]) {
    new string[128], query[128];
    if(!cache_get_row_count()) {
        SendClientMessage(playerid, Rouge, "Ce joueur n'existe pas !");
        return 1; }

    mysql_format(mysql, query, sizeof(query), "SELECT * FROM `joueurs` WHERE `Bannis`='1' AND `Username`='%s' LIMIT 1", nom);
    mysql_tquery(mysql, query, "", "");
    if((cache_get_row_int(0, 17)) != 1) {
        SendClientMessage(playerid, Rouge, "Ce joueur n'est pas bannis !");
        return 1; }
       
    mysql_format(mysql, query, sizeof(query),"UPDATE `joueurs` SET `Bannis` = '0', `RaisonBan`='' WHERE `Username` = '%e'", nom);
    mysql_tquery(mysql, query, "", "");
    GetPlayerName(playerid, joueuremetteur, sizeof(joueuremetteur));
    format(string, sizeof(string), "[Admin]:%s a unban %s.", joueuremetteur, nom);
    ChannelAdmin(Rouge, string);
    return 1;
}
that's the most you can optimize it... You welcome
You execute a query when you never do anything about it and the same query was executed before and the results are in that callback.

Quote:
Originally Posted by SwisherSweet
Посмотреть сообщение
u asked me in pm...
pawn Код:
public OnEssaiUnban(playerid, nom[]) {
    new string[128], query[128];
    if(!cache_get_row_count()) {
        SendClientMessage(playerid, Rouge, "Ce joueur n'existe pas !");
        return 1; }

    mysql_format(mysql, query, sizeof(query), "SELECT * FROM `joueurs` WHERE `Bannis`='1' AND `Username`='%s' LIMIT 1", nom);
    if((cache_get_row_int(0, 17)) != 1) {
        SendClientMessage(playerid, Rouge, "Ce joueur n'est pas bannis !");
        return 1; }
       
    mysql_format(mysql, query, sizeof(query),"UPDATE `joueurs` SET `Bannis` = '0', `RaisonBan`='' WHERE `Username` = '%e'", nom);
    GetPlayerName(playerid, joueuremetteur, sizeof(joueuremetteur));
    format(string, sizeof(string), "[Admin]:%s a unban %s.", joueuremetteur, nom);
    ChannelAdmin(Rouge, string);
    return 1;
}
Yes it is possible, You did'nt even need tquery...
You format a query with SELECT clause for no reason.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)