SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 13/02/2013, 09:57 AM   #1
dusk
High-roller
 
dusk's Avatar
 
Join Date: Jul 2008
Posts: 1,113
Reputation: 46
Default Loading a number from MYSQL

So the thing is i want OnPlayerSpawn i want to load the players money,and give it to him.
This is my script for it:
pawn Code:
new moneyquery[126];
    format(moneyquery,sizeof(moneyquery),"SELECT * FROM users WHERE username = '%s'",Name);
    mysql_query(moneyquery);
    mysql_store_result();
    new result[128];
    mysql_fetch_row_format(result, " ");
    sscanf(moneyquery,"i",PlayerInfo[playerid][money]);
    SetPVarInt(playerid, "money",PlayerInfo[playerid][money]);
    GivePlayerMoney(playerid, PlayerInfo[playerid][money]);
    return 1;

There's no errors,but still.. The money just doesn't appear.
dusk is offline   Reply With Quote
Old 13/02/2013, 10:12 AM   #2
Vince
Spam Machine
 
Vince's Avatar
 
Join Date: Sep 2007
Location: Belgium
Posts: 10,083
Reputation: 2655
Default Re: Loading a number from MYSQL

What is the purpose of fetching the entire row if you only need one field?

PHP Code:
SELECT money FROM users WHERE username '%s'
Then use mysql_fetch_int in R6 or earlier or strval in R7 and later.
__________________
Vince is offline   Reply With Quote
Old 13/02/2013, 10:32 AM   #3
dusk
High-roller
 
dusk's Avatar
 
Join Date: Jul 2008
Posts: 1,113
Reputation: 46
Default Re: Loading a number from MYSQL

THANKS a lot for that. Now my problem is that OnPlayerDisconnect it doesn't save the amount(and did yesterday)
pawn Code:
format(query,sizeof(query),"UPDATE users SET Money = '%d' WHERE username = '%s'",PlayerInfo[playerid][money],Name);
        mysql_query(query);
Do you see a problem?
dusk is offline   Reply With Quote
Old 13/02/2013, 11:46 AM   #4
dusk
High-roller
 
dusk's Avatar
 
Join Date: Jul 2008
Posts: 1,113
Reputation: 46
Default Re: Loading a number from MYSQL

I did. But this is my way of learning Thats why i'm asking
dusk is offline   Reply With Quote
Old 14/02/2013, 12:07 PM   #5
adsy
Huge Clucker
 
Join Date: Aug 2008
Posts: 410
Reputation: 3
Default Re: Loading a number from MYSQL

Is your field "Money" with a capital M or money without a capital M
adsy is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL lite loading number 48 from nowhere [WSF]ThA_Devil Scripting Help 2 20/04/2012 12:12 PM
Player Number in database [MYSQL] thimo Scripting Help 3 28/01/2012 04:23 PM
mysql loading. budelis Scripting Help 2 31/08/2011 07:51 PM
Problem with mysql phone number vection Help Archive 4 08/10/2010 10:40 PM
Mysql Number of rows? DarrenReeder Help Archive 9 17/04/2010 06:25 PM


All times are GMT. The time now is 10:19 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.