SA-MP Forums Archive
How many accounts in database - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: How many accounts in database (/showthread.php?tid=191244)



How many accounts in database - NewbBeginner - 18.11.2010

Hello

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

Thank you


Re: How many accounts in database - Kyle - 18.11.2010

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);



Re: How many accounts in database - [NoV]LaZ - 18.11.2010

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.


Re: How many accounts in database - JaTochNietDan - 18.11.2010

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)


Re: How many accounts in database - NewbBeginner - 18.11.2010

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


Re: How many accounts in database - JaTochNietDan - 18.11.2010

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();



Re: How many accounts in database - NewbBeginner - 18.11.2010

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



Re: How many accounts in database - Hiddos - 18.11.2010

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


Re: How many accounts in database - JaTochNietDan - 18.11.2010

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


Re: How many accounts in database - NewbBeginner - 18.11.2010

Thanks, Fixed It.