SQL query to count rows of a table // R33 - 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: SQL query to count rows of a table // R33 (
/showthread.php?tid=632363)
SQL query to count rows of a table // R33 -
YouHack - 12.04.2017
Hello,
I'm making a MyBB forum integeration for my gameserver so when people register on it the same thing will apply to forums ( so they will have access to forum too, automatically )
well i disabled registration and i made some edits to my code and i got errors on this:
PHP код:
stock CheckMybbUsers()
{
new query[1000];
format(query, sizeof(query), "SELECT * FROM `mybb_users`");
new Cache: stringresult = mysql_query(SQL, query);
cache_num_rows() = mybb_users;
cache_delete(stringresult);
return 1;
}
I'm using it to add +1 in UID ( user id ) for each registration...
errors are :
Код:
error 022: must be lvalue (non-constant)
warning 215: expression has no effect
in the check_num_rows line. can you help me with an alternative thing? or just by fixing errors on that?
P.s.: i tried cache_get_row_count() and got same error.
Re: SQL query to count rows of a table // R33 -
GangstaSunny. - 12.04.2017
I don't know the plugin but after 10 years of scripting i am pretty sure it have to be like:
PHP код:
mybb_users = cache_num_rows();
Re: SQL query to count rows of a table // R33 -
Vince - 13.04.2017
NEVER use num_rows if the only thing you're intersted in is a count of something. You do not need to process the entire resultset (which could be thousands of records) if you only want one single number.
PHP код:
SELECT COUNT(*) FROM `mybb_users`
That generates exactly one row with one column. Then retrieve that value like you would any other integer.
Quote:
Originally Posted by YouHack
I'm using it to add +1 in UID ( user id ) for each registration...
|
I'm pretty sure the mybb database uses auto_increment, i.e. it generates the id automatically for each new insert.
Re: SQL query to count rows of a table // R33 -
YouHack - 13.04.2017
Quote:
Originally Posted by GangstaSunny.
I don't know the plugin but after 10 years of scripting i am pretty sure it have to be like:
PHP код:
mybb_users = cache_num_rows();
|
well hahahah xD i made a big mistake hahah !
Re: SQL query to count rows of a table // R33 -
YouHack - 13.04.2017
and thanks vince, if that doesn't work i'll remove it so AUTO_INCREMENT will do its job