18.11.2010, 15:14
Hello
How can I get the number of all accounts in my database ? Mysql
Field ' Name '
Thank you
How can I get the number of all accounts in my database ? Mysql
Field ' Name '
Thank you
new count;
format(query,sizeof(query),"SELECT * FROM tablename'");
mysql_query(query);
mysql_store_result();
if(mysql_affected_rows())
{
count ++;
}
printf("count = %d",count);
new total;
mysql_query( "SELECT * FROM `table`;" );
mysql_store_result( )
total = mysql_num_rows( );
mysql_free_result( );
printf( "`table` has %d rows", total );
mysql_query('SELECT COUNT(Name) FROM `table`');
mysql_store_result();
printf("Number of accounts: %d", mysql_fetch_int());
mysql_free_result();
You could run a simple query to retrieve how many rows you have.
Assuming you're using G-sTyLeZzZ's MySQL plugin: pawn Код:
(The difference between my code and the other snippets posted before mine, is that the other snippets select all information in the table and store it, which is an unnecessary amount of processing) |
mysql_query('SELECT COUNT(*) FROM `table`');
mysql_store_result();
new string[50];
format(string,50,"Accounts registered: %d",mysql_fetch_int());
SendClientMessageToAll(color,string);
mysql_free_result();
(3548) : error 027: invalid character constant (3548) : error 017: undefined symbol "ELECT" (3548) : error 017: undefined symbol "COUNT" (3548) : fatal error 107: too many error messages on one line Compilation aborted.Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase 4 Errors.
mysql_query('SELECT COUNT(Name) FROM `players`');
mysql_query("SELECT COUNT(Name) FROM `players`");
mysql_query("SELECT COUNT(Name) FROM `players`");