SA-MP Forums Archive
count server accounts mysql [+REP] - 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 server accounts mysql [+REP] (/showthread.php?tid=576289)



count server accounts mysql [+REP] - simo0000 - 02.06.2015

when i use this cmd its show me that i have 83 accounts in my database but i have only 4 plz help me
pawn Код:
CMD:serverstats(playerid, params[])
{
    new total, query[128], Str[128];
    format(query, sizeof(query), "SELECT COUNT(*) FROM `Accounts`");
    mysql_query(mysql, query);
    mysql_store_result();
    mysql_free_result();
    format(Str, sizeof(Str), "Total Accounts : %i", query);
    SendClientMessage(playerid, -1, Str);
 return 1;
}

sorry for my bad english


Re: count server accounts mysql [+REP] - Stev - 02.06.2015

Use: mysql_num_rows();

Код:
new rows = mysql_nun_rows();
printf("Number of accounts: %d",rows);



Re: count server accounts mysql [+REP] - Vince - 02.06.2015

You're doing it completely wrong. You're not even fetching any value and you're trying to display the query (the entire "SELECT ..." part) as an integer. The reason it displays 83 is because that happens to be the ASCII value of 'S'.

I'm not familiar with the old style anymore, but you need to fetch the actual value between 'store' and 'free'.

Quote:
Originally Posted by Stev
Посмотреть сообщение
Use: mysql_num_rows();

Код:
new rows = mysql_nun_rows();
printf("Number of accounts: %d",rows);
Very, very bad practice if the only thing you're interested is one number. What do you think requires the least network traffic? Sending over one number or sending over an entire resultset composed of hundres, maybe thousands of rows?


Re: count server accounts mysql [+REP] - simo0000 - 02.06.2015

Quote:
Originally Posted by Stev
Посмотреть сообщение
Use: mysql_num_rows();

Код:
new rows = mysql_nun_rows();
printf("Number of accounts: %d",rows);
pawn Код:
CMD:serverstats(playerid, params[])
{
    new total, query[128], Str[128];
    format(query, sizeof(query), "SELECT * FROM `Accounts`");
    mysql_query(mysql, query);
    mysql_store_result();
    total = mysql_num_rows();
    mysql_free_result();
    format(Str, sizeof(Str), "Total Accounts : %i", total);
    SendClientMessage(playerid, -1, Str);
 return 1;
}
it's show me 0 Accounts


Re: count server accounts mysql [+REP] - Stev - 02.06.2015

Source: https://sampforum.blast.hk/showthread.php?tid=341737


Re: count server accounts mysql [+REP] - simo0000 - 02.06.2015

Quote:
Originally Posted by Stev
Посмотреть сообщение
Worked thnx +REP
rep me back if you want