SA-MP Forums Archive
Count total accounts - 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)
+--- Thread: Count total accounts (/showthread.php?tid=629220)



Count total accounts - Nin9r - 22.02.2017

Help:

Код HTML:
 new Cache: cachecheck = mysql_query(handle, "SELECT COUNT(playerID) from playeraccounts");
	numberaccounts = cache_get_row_count();
	cache_delete(cachecheck);
The result will be 1. What's wrong?


Re: Count total accounts - jlalt - 22.02.2017

Quote:
Originally Posted by Nin9r
Посмотреть сообщение
Help:

Код HTML:
 new Cache: cachecheck = mysql_query(handle, "SELECT COUNT(playerID) from playeraccounts");
	numberaccounts = cache_get_row_count();
	cache_delete(cachecheck);
The result will be 1. What's wrong?
Well, I didn't use count so far but this supposed to.work:
Код HTML:
 new Cache: cachecheck = mysql_query(handle, "SELECT null from playeraccounts");
	numberaccounts = cache_get_row_count();
	cache_delete(cachecheck);



Re: Count total accounts - Nin9r - 22.02.2017

It works, thank you so much ! +rep


Re: Count total accounts - X337 - 22.02.2017

I would suggest you to use select count(*) instead of selecting all rows because it may affect your script performance or may hangs your server (as i see you're using unthreaded query) if the table have many rows.
Here's an example to get total rows:
Код:
	new Cache:cachecheck = mysql_query(handle, "SELECT COUNT(playerID) AS total from playeraccounts");
	numberaccounts = cache_get_field_content_int(0, "total");
	cache_delete(cachecheck);