mysql counting rows in accounts table -
Filbert - 20.05.2020
So I just put this to my register action :
PHP Code:
...
new registered[24], Cache:aresult = mysql_query(mysql, "SELECT COUNT(*) FROM `accounts`");
cache_get_field_content_int(0, registered, mysql);
cache_delete(aresult);
format(string, sizeof(string), "{FFFF00}%s [%d] has successfully registered. [Total Accounts: %d]", pName(playerid), playerid, registered);
SendClientMessageToAll(yellow, string);
...
But it shows "Player_Name [0] has successfully registered. [Total Accounts: 0]"
Why is it becomes 0? There are 3 rows in the table
Re: mysql counting rows in accounts table -
jasperschellekens - 20.05.2020
Try this:
pawn Code:
mysql_query(mysql, "SELECT * FROM `accounts`"); // I always use SELECT ID or something else rather than everything (*)
new rows;
cache_get_row_count(rows);
format(string, sizeof(string), "{FFFF00}%s [%d] has successfully registered. [Total Accounts: %d]", pName(playerid), playerid, rows);
Re: mysql counting rows in accounts table -
Filbert - 21.05.2020
Quote:
Originally Posted by jasperschellekens
Try this:
pawn Code:
mysql_query(mysql, "SELECT * FROM `accounts`"); // I always use SELECT ID or something else rather than everything (*)
new rows; cache_get_row_count(rows);
format(string, sizeof(string), "{FFFF00}%s [%d] has successfully registered. [Total Accounts: %d]", pName(playerid), playerid, rows);
|
It still says that i have 0 players registered. Or should I make it tquery?
Re: mysql counting rows in accounts table -
SharpenBlade - 21.05.2020
Count begins from 0 as far as I know.
Re: mysql counting rows in accounts table -
Calisthenics - 21.05.2020
Code:
cache_get_field_content_int(0, registered, mysql);
pawn Code:
native cache_get_field_content_int(row, const field_name[], connectionHandle = 1);
It expects a column name to search for but `registered` is empty. The correct way would be:
pawn Code:
new Cache:aresult = mysql_query(mysql, "SELECT COUNT(*) AS total_accounts FROM `accounts`"),
registered = cache_get_field_content_int(0, "total_accounts", mysql);
or
pawn Code:
new Cache:aresult = mysql_query(mysql, "SELECT COUNT(*) FROM `accounts`"),
registered = cache_get_row_int(0, 0, mysql);
But you do not need a SELECT query at all. When you execute an INSERT query with auto increment, you retrieve the number generated (account ID) with `cache_insert_id`. This is how many players have registered (including deleted accounts).
Re: mysql counting rows in accounts table -
SiaReyes - 21.05.2020
Code:
new total = cache_insert_id();
format(string, sizeof(string), "{FFFF00}%s [%d] has successfully registered. [Total Accounts: %d]",pName(playerid), playerid, total);
Re: mysql counting rows in accounts table -
Filbert - 21.05.2020
Quote:
Originally Posted by Calisthenics
Code:
cache_get_field_content_int(0, registered, mysql);
pawn Code:
native cache_get_field_content_int(row, const field_name[], connectionHandle = 1);
It expects a column name to search for but `registered` is empty. The correct way would be:
pawn Code:
new Cache:aresult = mysql_query(mysql, "SELECT COUNT(*) AS total_accounts FROM `accounts`"), registered = cache_get_field_content_int(0, "total_accounts", mysql);
or
pawn Code:
new Cache:aresult = mysql_query(mysql, "SELECT COUNT(*) FROM `accounts`"), registered = cache_get_row_int(0, 0, mysql);
But you do not need a SELECT query at all. When you execute an INSERT query with auto increment, you retrieve the number generated (account ID) with `cache_insert_id`. This is how many players have registered (including deleted accounts).
|
Thanks.. It's working. I just need to make it "register+1" to include the registered player... REP+