How many accounts in database
#1

Hello

How can I get the number of all accounts in my database ? Mysql
Field ' Name '

Thank you
Reply
#2

pawn Код:
new count;
format(query,sizeof(query),"SELECT * FROM tablename'");
mysql_query(query);

mysql_store_result();

if(mysql_affected_rows())
{
    count ++;
}
printf("count = %d",count);
Reply
#3

pawn Код:
new total;
mysql_query( "SELECT * FROM `table`;" );
mysql_store_result( )
total = mysql_num_rows( );
mysql_free_result( );

printf( "`table` has %d rows", total );
The number of rows will be stored in the 'total' variable.
Reply
#4

You could run a simple query to retrieve how many rows you have.

Assuming you're using G-sTyLeZzZ's MySQL plugin:

pawn Код:
mysql_query('SELECT COUNT(Name) FROM `table`');
mysql_store_result();
printf("Number of accounts: %d", mysql_fetch_int());
mysql_free_result();
Hope that helps!

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

Quote:
Originally Posted by JaTochNietDan
Посмотреть сообщение
You could run a simple query to retrieve how many rows you have.

Assuming you're using G-sTyLeZzZ's MySQL plugin:

pawn Код:
mysql_query('SELECT COUNT(Name) FROM `table`');
mysql_store_result();
printf("Number of accounts: %d", mysql_fetch_int());
mysql_free_result();
Hope that helps!

(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)
And how can I display it.

That before your post, it says only 1 player, but there is around 500.

EDIT: Got it
Reply
#6

What do you want to display it in? For example if you want to tell people on the server:

pawn Код:
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();
Reply
#7

Код:
(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`');
Reply
#8

pawn Код:
mysql_query("SELECT COUNT(Name) FROM `players`");
Rofl. You still used the symbol ' instead of "
Reply
#9

Woops, that's my PHP brain taking over, those aren't the Pawn string characters

pawn Код:
mysql_query("SELECT COUNT(Name) FROM `players`");
Should be double quotes instead of apostrophe!

Edit: Hiddos is too fast
Reply
#10

Thanks, Fixed It.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)