Getting the number of rows using Blue G's MySQL
#1

So I'm trying to make a simple /factions command which will go through the database and see how many players are in a specific faction. Currently I have this:

pawn Код:
CMD:factions(playerid, params[])
{
    new str[128];
    for(new f; f < MAX_FACTIONS; f++)
    {
        if(FactionInfo[f][FactionType] != 0)
        {
            // Faction Exists
            format(str, 128, "[FID: %d] Name: %s | Members: %d", f, FactionInfo[f][FactionName], GetFactionMembers(f));
            SendClientMessage(playerid, -1, str);
        }
    }
    return 1;
}

stock GetFactionMembers(factionid)
{
    new query[200];
   
    mysql_format(con, query, sizeof(query), "SELECT * FROM `players` WHERE `faction` = '%d'", factionid);
    mysql_tquery(con, query, "Actual_GetFactionMembers", "i", factionid);
    return 1;
}

stock Actual_GetFactionMembers(factionid)
{
    new str[128];
   
    format(str, 128, "%d", cache_get_row_count());
    return str;
}
Unfortunately, this isn't working as it's returning 1 for each faction when it should only return 1 for one faction, and 0 for the rest. I feel like I'm using the wrong function where "cache_get_row_count()" is, but I'm not sure what the correct function is. Any help would be appreciated. Thanks!
Reply
#2

Abagail's right, you're returning one anyways.

I would do it like this
pawn Код:
CMD:factions(playerid, params[])
{
    new str[128];
    for(new f; f < MAX_FACTIONS; f++)
    {
        if(FactionInfo[f][FactionType] != 0)
        {
            new query[200];
            mysql_format(con, query, sizeof(query), "SELECT * FROM `players` WHERE `faction` = '%d'", factionid);
            mysql_tquery(con, query, "GetFactionMembers", "ii", playerid, factionid);
        }
    }
    return 1;
}

stock GetFactionMembers(playerid, factionid)
{
    format(str, 128, "[FID: %d] Name: %s | Members: %d", f, FactionInfo[f][FactionName], cache_get_row_count());
    SendClientMessage(playerid, -1, str);
    return 1;
}
Reply
#3

Your code logic makes no sense at all. Why would you always return 1 as the amount of faction members? You should pass all data you need to the callback and then call it & send the message directly inside the callback.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)