SQL query to count rows of a table // R33
#1

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(querysizeof(query), "SELECT * FROM `mybb_users`");
    new 
Cachestringresult mysql_query(SQLquery);
    
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.
Reply
#2

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

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.
Reply
#4

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 !
Reply
#5

and thanks vince, if that doesn't work i'll remove it so AUTO_INCREMENT will do its job
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)