Problem with getting data from database
#1

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$
Reply
#2

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;

}
Reply
#3

Thank you!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)