Problem with getting data from database - 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: Problem with getting data from database (
/showthread.php?tid=536267)
[Solved]Problem with getting data from database -
TheRox - 08.09.2014
Hello, i'm trying to create a simple CMD that shows how much money i have in the bank (table playerdata > field: money)
So this is the code
pawn Код:
CMD:checkbank(playerid, params[]){
new query[400];
new data[900];
format(query, sizeof(query), "SELECT `money` FROM playerdata WHERE user = '%s'", GetName(playerid));
mysql_query(query);
mysql_store_result();
new money[100];
new balance = mysql_fetch_row_format(money,"money");
format(data, sizeof(data), "Your balance is now: %d $", balance);
SendClientMessage(playerid, COLOR_YELLOW, data);
printf("DEBUG QUERY>> %s", query); // Ignore this
mysql_free_result();
return 1;
}
The problem is that it shows 1$ instead of 3000$
Re: Problem with getting data from database -
dusk - 08.09.2014
mysql_fetch_row_format returns 1 if the function succeeded.
To get that one integer value you could use mysql_fetch_int like so:
pawn Код:
CMD:checkbank(playerid, params[]){
new query[400];
new data[900];
format(query, sizeof(query), "SELECT `money` FROM playerdata WHERE user = '%s'", GetName(playerid));
mysql_query(query);
mysql_store_result();
new money[100];
new balance = mysql_fetch_int();
format(data, sizeof(data), "Your balance is now: %d $", balance);
SendClientMessage(playerid, COLOR_YELLOW, data);
printf("DEBUG QUERY>> %s", query); // Ignore this
mysql_free_result();
return 1;
}
Re: Problem with getting data from database -
TheRox - 08.09.2014
Thank you!