Command list
#1

Hello!


I have command /factions which showing all the factions of my server.
The problem is that is showing just those factions who have more than 1 member.

How to change the query to show all the factions even if one of them is empty?


Command:

Код HTML:
CMD:factions(playerid, params[])
{
    #pragma unused params
    new
        output[1024] = "Name\tMembers\tStats\tLv",
        Cache:result7 = mysql_query(handle, "SELECT playerGroup, COUNT(*) AS members FROM playeraccounts GROUP BY playerGroup HAVING members > 0 ORDER BY playerGroup");
    for(new i, j = cache_get_row_count(); i < j; i++)
    {
        new
            groupId = cache_get_row_int(i, 0, handle),
            members = cache_get_row_int(i, 1, handle);

        if(0 <= groupId < 16)
        {
            new temp[128];
            format(temp, sizeof(temp),"{%s}%s\t[%d/%d]\t%s\tLevel %d\n",
                groupVariables[groupId][gColor],
                groupVariables[groupId][gGroupName],
                members,
                groupVariables[groupId][gSlots],
                (groupVariables[groupId][gGroupAplication] == 1) ? ("Recruit") : ("Don't recruit"),
                groupVariables[groupId][gGroupLvl]
            );

			strcat(output, temp);
        }

    }

    cache_delete(result7);
    ShowPlayerDialog(playerid, 4500, DIALOG_STYLE_TABLIST_HEADERS, "Factions", output, "Select", "Cancel");
    return 1;
}
What I tried?

I tried to change

Код HTML:
mysql_query(handle, "SELECT playerGroup, COUNT(*) AS members FROM playeraccounts GROUP BY playerGroup HAVING members > 0 ORDER BY playerGroup");
to

Код HTML:
mysql_query(handle, "SELECT playerGroup, COUNT(*) AS members FROM playeraccounts GROUP BY playerGroup ORDER BY playerGroup");
and

Код HTML:
mysql_query(handle, "SELECT playerGroup, COUNT(*) AS members FROM playeraccounts GROUP BY playerGroup HAVING members >= 0 ORDER BY playerGroup");
Reply
#2

Do you still need help with this?
Reply
#3

This should work fine, in your MySQL Query you are limiting the factions to those with more than one member.

new mysqlQuery;

mysqlQuery = "SELECT playerGroup, COUNT(*) AS members FROM playeraccounts GROUP BY playerGroup ORDER BY playerGroup"

mysql_query(handle, mysqlQuery);
Reply
#4

Why u SELECT * FROM playeraccounts, when u need to SELECT * FROM factions.
Reply
#5

doesn't work... any ideas?
Reply
#6

As @kingmc said , you cant select from playeraccounts because it will only display the factions with atleast one member. You have to make a separate table for factions and work around that table.
Reply
#7

i have already that table named 'factions'. can i make a query to list all the factions from there and show some other informations from playeraccounts?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)