count server accounts mysql [+REP]
#1

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
Reply
#2

Use: mysql_num_rows();

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

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?
Reply
#4

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
Reply
#5

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

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


Forum Jump:


Users browsing this thread: 1 Guest(s)