SA-MP Forums Archive
/checkregistered - 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: /checkregistered (/showthread.php?tid=436619)



/checkregistered - Tanush123 - 12.05.2013

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?


Re: /checkregistered - Kwarde - 12.05.2013

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


Re: /checkregistered - Tanush123 - 12.05.2013

Well i use mysql


Re: /checkregistered - Vince - 12.05.2013

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



Re: /checkregistered - Kwarde - 12.05.2013

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)


Re: /checkregistered - Tanush123 - 12.05.2013

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


Re: /checkregistered - Emmet_ - 12.05.2013

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;
}



Re: /checkregistered - Tanush123 - 12.05.2013

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;
}



Re: /checkregistered - Tanush123 - 14.05.2013

bump


Re: /checkregistered - Vince - 14.05.2013

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.