String and textdraw problem - 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: String and textdraw problem (
/showthread.php?tid=474710)
String and textdraw problem -
DCatalin - 09.11.2013
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

.
Re: String and textdraw problem -
-=Dar[K]Lord=- - 09.11.2013
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
Re: String and textdraw problem -
DCatalin - 09.11.2013
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");
Re: String and textdraw problem -
-=Dar[K]Lord=- - 09.11.2013
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
Re: String and textdraw problem -
DCatalin - 09.11.2013
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 )
Re: String and textdraw problem -
KingHual - 09.11.2013
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.
Re: String and textdraw problem -
DCatalin - 09.11.2013
Solved, please close this topic.