Count Issue - 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: Count Issue (
/showthread.php?tid=318150)
Count Issue -
Abreezy - 14.02.2012
pawn Код:
stock LoadFactions()
{
new Query[400];
fcount = 0;
for(new id = 0;id<MAX_FACTIONS;id++)
{
format(Query, sizeof(Query), "SELECT * FROM Factions WHERE ID = %d", id);
mysql_query(Query);
mysql_store_result();
fcount++;
if(mysql_num_rows() != 0)
{
if(mysql_fetch_row_format(Query, "|"))
{
sscanf(Query, "p<|>s[30]dd",
FactionInfo[id][Name],
FactionInfo[id][Type],
FactionInfo[id][FBank]);
printf("%s | %d | %d", FactionInfo[id][Name],FactionInfo[id][Type],FactionInfo[id][FBank]);
}
}
}
printf("%i Faction Loaded",fcount);
return 1;
}
I have this code, and i want it to count each faction it has found on the database. For starters, the printf(%s | etc doesn't show up in the console, at all, so I'm guess it doesnt load up at all. How could I fix this issue, and also count each faction found? Thanks in advance.
Re: Count Issue -
[HiC]TheKiller - 14.02.2012
Why would you loop MAX_FACTIONS amount of queries? I'm pretty sure I've said before not to do that with your code to you. Use mysql_retrieve_row to just go through all the lines in the database. You also never free the result

.
pawn Код:
stock LoadFactions()
{
new id = 0, rowfetch[300];
mysql_query("SELECT * FROM Factions");
mysql_store_result();
while(mysql_retrieve_row())
{
id ++;
mysql_fetch_row_format(rowfetch, "|")
sscanf(rowfetch, "p<|>s[30]dd", FactionInfo[id][Name], FactionInfo[id][Type], FactionInfo[id][FBank]);
printf("%s | %d | %d", FactionInfo[id][Name],FactionInfo[id][Type],FactionInfo[id][FBank]);
}
printf("%i Factions Loaded",id);
mysql_free_result();
return 1;
}
Re: Count Issue -
Abreezy - 14.02.2012
Whoops. Thanks, I was just trying something like this and failed lol
pawn Код:
stock LoadFactions()
{
new str[400];
fcount = 0;
new index;
mysql_query("SELECT * FROM `Factions`");
mysql_store_result();
if(mysql_num_rows() > 0)
{
while(mysql_fetch_row(str))
{
sscanf(str, "p<|>ds[30]dd",
FactionInfo[index][ID],
FactionInfo[index][Name],
FactionInfo[index][Type],
FactionInfo[index][FBank]);
printf("%s | %d | %d glsgs", FactionInfo[index][Name],FactionInfo[index][Type],FactionInfo[index][FBank]);
fcount++;
}
}
mysql_free_result();
printf("Loaded %d factions",index);
return 1;
}
I'll try yours.
Re: Count Issue -
Abreezy - 14.02.2012
"[22:37:58] | 0 | 0
[22:37:58] 1 Factions Loaded"
Is what is shows :/ It has values tho on the PHPMYADMIN.
Re: Count Issue -
KingHual - 14.02.2012
I'm pretty sure you can get rid of the loop and use the MYSQL SELECT COUNT query. ****** it since i'm on my phone now.
Re: Count Issue -
[HiC]TheKiller - 14.02.2012
under OnGameModeInit and then paste your mysql log in your server directory.
Re: Count Issue -
Abreezy - 14.02.2012
It doesn't show up in my mysql log and yes i have debug 1
edit: it does now
pawn Код:
CMySQLHandler::Query(SELECT * FROM Factions) - Successfully executed.
[23:20:34] >> mysql_store_result( Connection handle: 1 )
[23:20:34] CMySQLHandler::StoreResult() - Result was stored.
[23:20:34] >> mysql_retrieve_row( Connection handle: 1 )
[23:20:34] >> mysql_fetch_row_format( Connection handle: 1 )
[23:20:34] >> mysql_retrieve_row( Connection handle: 1 )
[23:20:34] >> mysql_free_result( Connection handle: 1 )
[23:20:34] CMySQLHandler::FreeResult() - Result was successfully free'd.
Re: Count Issue -
Abreezy - 14.02.2012
bump