CMD:factions(playerid,params[])
{
mysql_tquery(mysql, "SELECT * FROM `Factions` LIMIT "#MAX_FACTIONS"", "LoadFactionsIG", "i",playerid);
mysql_tquery(mysql, "SELECT * FROM `accounts` LIMIT "#MAX_FACTIONS"", "LoadFactionsIG", "i",playerid);
return 1;
}
forward LoadFactionsIG(playerid);
public LoadFactionsIG(playerid)
{
if(playerid == INVALID_PLAYER_ID) return 1;
new rows,fields,str[160];
cache_get_data(rows,fields,mysql);
if(!rows) return 1;
new fracName[32];
for (new i; i < rows; i++)
{
cache_get_field_content_int(i, "factionid");
cache_get_field_content(i, "Name",fracName,mysql);
format(str, sizeof(str), "%s%s \n",str,fracName);
}
ShowPlayerDialog(playerid, 10, DIALOG_STYLE_MSGBOX, "Factions", str, "OK","");
return 1;
}


SELECT factionid, COUNT(factionid) AS memberCount FROM Accounts GROUP BY factionid
SELECT a.factionid, f.Name, COUNT(a.factionid) AS memberCount FROM Accounts a INNER JOIN Faction f ON f.ID = a.factionid GROUP BY a.factionid, f.Name
|
You'll want to use "group by". Bascially what you want to do is this:
PHP код:
PHP код:
|
|
PHP код:
|
cache_get_field_content_int(row, "memberCount", handle); or cache_get_row_int(row, 2, handle);
|
Use this:
@Vince, I tried it on a database and it did work. It's amazing how powerful the SQLanguage is. And then inside of the callback, use: Код:
cache_get_field_content_int(row, "memberCount", handle); or cache_get_row_int(row, 2, handle); Both of them will return the member count. Also, don't bump before 24 hours. The rules are in every section of the forum for a reason. |
CMD:factions(playerid,params[])
{
mysql_tquery(mysql, "SELECT * FROM `Factions` LIMIT "#MAX_FACTIONS"", "LoadFactionsIG", "i",playerid);
return 1;
}
forward LoadFactionsIG(playerid);
public LoadFactionsIG(playerid)
{
if(playerid == INVALID_PLAYER_ID) return 1;
new rows,fields,str[160];
cache_get_data(rows,fields,mysql);
if(!rows) return 1;
new fracName[32];
for (new i; i < rows; i++)
{
cache_get_field_content_int(i, "factionid");
cache_get_field_content(i, "Name",fracName,mysql);
format(str, sizeof(str), "%s%s \n",str,fracName);
}
ShowPlayerDialog(playerid, 10, DIALOG_STYLE_MSGBOX, "Factions", str, "OK","");
return 1;
}
CMD:factions(playerid,params[])
{
mysql_tquery(mysql, "SELECT a.factionid, f.Name, COUNT(a.factionid) AS memberCount FROM `Accounts` a INNER JOIN `Faction` f ON f.ID = a.factionid GROUP BY a.factionid, f.Name", "LoadFactionsIG", "i", playerid);
return 1;
}
forward LoadFactionsIG(playerid);
public LoadFactionsIG(playerid)
{
if(!IsPlayerConnected(playerid))
return 1;
new rows = cache_get_row_count(mysql);
if(!rows)
return 1;
new fName[32], dString[MAX_FACTIONS * (32+6) +1];
for (new i; i < rows; i++)
{
cache_get_field_content(i, "Name", fName, mysql);
format(dString, sizeof(dString), "%s%s\t%i\n", dString, fName, cache_get_field_content_int(i, "memberCount", mysql));
}
ShowPlayerDialog(playerid, 10, DIALOG_STYLE_MSGBOX, "Factions", dString, "OK","");
return 1;
}
CMD:factions(playerid,params[])
{
mysql_tquery(mysql, "SELECT * FROM `Factions` LIMIT "#MAX_FACTIONS"", "LoadFactionsIG", "i",playerid);
return 1;
}
forward LoadFactionsIG(playerid);
public LoadFactionsIG(playerid)
{
if(playerid == INVALID_PLAYER_ID) return 1;
new rows,fields,str[160];
cache_get_data(rows,fields,mysql);
if(!rows) return 1;
new fracName[32];
for (new i; i < rows; i++)
{
cache_get_field_content_int(i, "factionid");
cache_get_field_content(i, "Name",fracName,mysql);
format(str, sizeof(str), "%s%s \n",str,fracName);
}
ShowPlayerDialog(playerid, 10, DIALOG_STYLE_MSGBOX, "Factions", str, "OK","");
return 1;
}
"ID" refers to faction ID.
"factionid" refers to Faction ID.
CMD:factions(playerid,params[])
{
mysql_tquery(mysql, "SELECT a.factionid, f.Name, COUNT(a.factionid) AS memberCount FROM `Accounts` a INNER JOIN `Faction` f ON f.ID = a.factionid GROUP BY a.factionid, f.Name", "LoadFactionsIG", "i", playerid);
return 1;
}
forward LoadFactionsIG(playerid);
public LoadFactionsIG(playerid)
{
if(!IsPlayerConnected(playerid))
return 1;
new rows = cache_get_row_count(mysql);
if(!rows)
return 1;
new fName[32] fID, dString[MAX_FACTIONS * (32+6) +1], count, id, pool_size = GetPlayerPoolSize();
for (new i; i < rows; i++)
{
count = 0;
cache_get_field_content(i, "Name", fName, mysql);
fID = cache_get_field_content_int(i, "factionid", mysql);
for (id = 0; id <= pool_size; id++)
{
if (PlayerInfo[id][Faction] == fID) // Replace PlayerInfo with your enum
count++;
}
format(dString, sizeof(dString), "%s%s\t%i/%i\n", dString, fName, count, cache_get_field_content_int(i, "memberCount", mysql));
}
ShowPlayerDialog(playerid, 10, DIALOG_STYLE_MSGBOX, "Factions", dString, "OK","");
return 1;
}
enum PlayerData
{
ID,
Name[MAX_PLAYER_NAME],
Password[129],
IP[16],
Admin,
VIP,
FactionID,
FactionName[200],
FactionRank[32],
Money,
Float:posX,
Float:posY,
Float:posZ,
Float:posA
};
new Player[MAX_PLAYERS][PlayerData];
enum faction // Enums, way better then using 10 variables per thing needed for faction system.
{
ID, // Faction ID
Name[32], // Name of the faction
Type, // What kind of faction? Criminal, law, etc
Rank1[32], // Rank Name
Rank2[32], // Rank Name
Rank3[32], // Rank Name
Rank4[32], // Rank Name
Rank5[32] // Rank Name
};