Getting the number of rows using Blue G's 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)
+--- Thread: Getting the number of rows using Blue G's MySQL (
/showthread.php?tid=584686)
Getting the number of rows using Blue G's MySQL -
2KY - 07.08.2015
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!
Re: Getting the number of rows using Blue G's MySQL -
xVIP3Rx - 07.08.2015
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;
}
Re: Getting the number of rows using Blue G's MySQL -
Abagail - 07.08.2015
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.