String and textdraw problem
#1

Hello, i have a little problem. I want to make a textdraw that shows total accounts, but i have a problem, it shows total accounts: 1, instead of correct number of accounts, i have tried to put string in other way, but i have the same problem.

pawn Код:
new acctext[64];

new totalaccstring = mysql_query("SELECT COUNT(id) as total FROM players");
format(acctext, sizeof(acctext), "Total accounts: %d", totalaccstring);

TextDrawSetString(totalacc, acctext);
TextDrawShowForPlayer(playerid, totalacc); //totalacc is the textdraw.

Sorry for bad english .
Reply
#2

pawn Код:
new acctext[64];
new totalaccs;
mysql_query("SELECT * FROM players");
mysql_store_result();
mysql_fetch_field_row(totalaccs,"STRINGWHICHHOLDSTHECOUNT");//Change the "STRINGWHICHHOLDSTHECOUNT" with your var which saves the total count
mysql_free_result();
format(acctext, sizeof(acctext), "Total accounts: %d", totalaccs);

TextDrawSetString(totalacc, acctext);
TextDrawShowForPlayer(playerid, totalacc); //totalacc is the textdraw.
Should Work try it out

#EDITED: My bad, code was kinda wrong
Reply
#3

Quote:
Originally Posted by -=Dar[K]Lord=-
Посмотреть сообщение
pawn Код:
new acctext[64];
new totalaccs;
mysql_query("SELECT * FROM players");
mysql_store_result();
mysql_fetch_field_row(totalaccs,"STRINGWHICHHOLDSTHECOUNT");//Change the "STRINGWHICHHOLDSTHECOUNT" with your var which saves the total count
mysql_free_result();
format(acctext, sizeof(acctext), "Total accounts: %d", totalaccs);

TextDrawSetString(totalacc, acctext);
TextDrawShowForPlayer(playerid, totalacc); //totalacc is the textdraw.
Should Work try it out

#EDITED: My bad, code was kinda wrong
pawn Код:
(17308) : error 035: argument type mismatch (argument 1)

17308: mysql_fetch_field_row(totalaccs, "id");
Reply
#4

pawn Код:
new acctext[64];
new totalaccs;
new TotalAccStr[256];
mysql_query("SELECT * FROM players");
mysql_store_result();
mysql_fetch_field_row(TotalAccStr,"STRINGWHICHHOLDSTHECOUNT");//Change the "STRINGWHICHHOLDSTHECOUNT" with your var which saves the total count
totalaccs = strval(TotalAccStr);
format(acctext, sizeof(acctext), "Total accounts: %d", totalaccs);

TextDrawSetString(TotalAccStr, acctext);
TextDrawShowForPlayer(playerid, totalacc); //totalacc is the textdraw.
mysql_free_result();
Try now , should work
Reply
#5

Compiled, but server don't starts.

Debug:

Код:
[17:47:07] CMySQLHandler::Connect() - Connection was successful.

[17:47:07] CMySQLHandler::Connect() - Auto-Reconnect has been enabled.

[17:47:07] >> mysql_query( Connection handle: 1 )

[17:47:07] CMySQLHandler::Query(SELECT * FROM players) - Successfully executed.

[17:47:07] >> mysql_store_result( Connection handle: 1 )

[17:47:07] CMySQLHandler::StoreResult() - Result was stored.

[17:47:07] >> mysql_fetch_field_row( Connection handle: 1 )
Reply
#6

Quote:
Originally Posted by -=Dar[K]Lord=-
Посмотреть сообщение
pawn Код:
new acctext[64];
new totalaccs;
mysql_query("SELECT * FROM players");
mysql_store_result();
mysql_fetch_field_row(totalaccs,"STRINGWHICHHOLDSTHECOUNT");//Change the "STRINGWHICHHOLDSTHECOUNT" with your var which saves the total count
mysql_free_result();
format(acctext, sizeof(acctext), "Total accounts: %d", totalaccs);

TextDrawSetString(totalacc, acctext);
TextDrawShowForPlayer(playerid, totalacc); //totalacc is the textdraw.
Should Work try it out

#EDITED: My bad, code was kinda wrong
NEVER use SELECT * to get row count. That's what SELECT COUNT is for.
Reply
#7

Solved, please close this topic.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)