/checkregistered
#1

Well i want to make a command called /checkregistered. What it does is it will show how many people registered. So i got a table called "PlayerID". What it does is it shows the ID and Name.
Since i was the first person to register, it shows
"1 Tan"

And my friend was second
"2 Tommy_Di_Giovanni

I also got a column in my accounts database Called "PID", what it has is it shows the ID like the one above. I use zcmd, is it possible to make a command telling how many people registered using of those tables. If so, how?
Reply
#2

This is possible yes!
Do you use MySQL, SQLite, DJson? What are you using, I simply mean
Reply
#3

Well i use mysql
Reply
#4

PHP код:
SELECT COUNT(*) FROM accounts
Reply
#5

Then you can loop through the accounts, and with format() you can create the message with the data off course and send it to you (Off course you should send a client message in every loop instead of formatting the whole data first, because of the 128 limit. But I think you figured out as much)
Reply
#6

So this is what i did
pawn Код:
CMD:checkregistered(playerid,params[])
{
    new totalreg;
    mysql_query("SELECT COUNT(Name) FROM accounts");
    totalreg = mysql_num_rows();
    format(str,sizeof(str),"%d has registered on the server.",totalreg);
    SCM(playerid,lightgreen,str);
    return 1;
}
I get -1
Reply
#7

You forgot to store and free the result, therefore mysql_num_rows returned -1 because no result was stored and the function couldn't retrieve any data.

Try this instead:

pawn Код:
CMD:checkregistered(playerid,params[])
{
    new totalreg;
    mysql_query("SELECT COUNT(*) FROM accounts");
    mysql_store_result(); // IMPORTANT
    totalreg = mysql_num_rows();
    mysql_free_result();
    format(str,sizeof(str),"%d has registered on the server.",totalreg);
    SCM(playerid,lightgreen,str);
    return 1;
}
Reply
#8

I get 1 now
Код:
[01:07:19] CMySQLHandler::Query(SELECT COUNT(*) FROM accounts) - Successfully executed.
[01:07:19] >> mysql_store_result( Connection handle: 1 )
pawn Код:
CMD:checkregistered(playerid,params[])
{
    new totalreg;
    mysql_query("SELECT COUNT(*) FROM accounts");
    mysql_store_result(); // IMPORTANT
    totalreg = mysql_num_rows();
    mysql_free_result();
    format(str,sizeof(str),"%d people have registered on the server.",totalreg);
    SCM(playerid,lightgreen,str);
    return 1;
}
Reply
#9

bump
Reply
#10

Why don't you execute queries in phpMyAdmin first to see what they produce? The count() function ALWAYS returns only a single field that contains the number of rows in the table. i.e.

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)