SA-MP Forums

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

 
 
Thread Tools Display Modes
Old 08/06/2010, 03:25 PM   #1
oliverrud
Huge Clucker
 
Join Date: Apr 2009
Location: Denmark
Posts: 415
Reputation: 24
Default MySQL query question.

Hey, is it possible to like instead of:
pawn Code:
format(string,300,"UPDATE `SQL_FACTION` SET `Bank`='%s' WHERE `ID`='2'",inputtext);

then do some mysql query that would plus the inputtext with the current numbers in the bank?
oliverrud is offline  
Old 08/06/2010, 03:43 PM   #2
Ignas1337
Gangsta
 
Join Date: Jul 2007
Posts: 546
Reputation: 1
Default Re: MySQL query question.

by plus i assume you mean add up, or sum. well i haven't heard of an mysql function that does that, so you should :
1. Extract data
2. Alter it (in your case, sum, add up, plus, what is needed)
3. Update data
Ignas1337 is offline  
Old 08/06/2010, 03:46 PM   #3
Aleksandar_Zivanovci
Big Clucker
 
Join Date: Apr 2010
Posts: 84
Reputation: 0
Default Re: MySQL query question.

Code:
format(string,300,"UPDATE `SQL_FACTION` SET `Bank`=Bank + %d WHERE `ID`='2'",strval(inputtext));
if you wanted this
Aleksandar_Zivanovci is offline  
Old 08/06/2010, 04:04 PM   #4
oliverrud
Huge Clucker
 
Join Date: Apr 2009
Location: Denmark
Posts: 415
Reputation: 24
Default Re: MySQL query question.

Aleksandar you made my day ^^

Thanks Izanagi for telling me the information.
oliverrud is offline  
Old 08/06/2010, 04:07 PM   #5
oliverrud
Huge Clucker
 
Join Date: Apr 2009
Location: Denmark
Posts: 415
Reputation: 24
Default Re: MySQL query question.

Oh yea I got one problem left I hope one of you can help me solve:

pawn Code:
if(IsNumeric(inputtext))
        {
        new moneycheck[128];
        format(moneycheck,128,"%s",inputtext);
            if(GetPlayerMoney(playerid) < moneycheck)
            {
                SendClientMessage(playerid, 0xFFFFFF, "You don't have enough cash.");
            }
            else
            {
                GivePlayerMoney(playerid, -moneycheck);
            new string2[128];
                format(string,300,"UPDATE "SQL_FACTION" SET `FactionBank`=FactionBank + %d WHERE `ID`='2'",strval(inputtext));
                mysql_query(string);
                format(string,128,"You have just deposit %s into HR313SR Faction Bank",inputtext);
                SendClientMessage(playerid,COLOR_YELLOW,string2);
            }
        }

I'm having error at the:

pawn Code:
if(GetPlayerMoney(playerid) < moneycheck)
pawn Code:
GivePlayerMoney(playerid, -moneycheck);

Errors is following:

Code:
error 035: argument type mismatch (argument 2)
error 033: array must be indexed (variable "moneycheck")
oliverrud is offline  
Old 08/06/2010, 04:11 PM   #6
Sascha
High-roller
 
Sascha's Avatar
 
Join Date: Jul 2009
Location: Germany
Posts: 1,494
Reputation: 70
Default Re: MySQL query question.

use:
Code:
strval(moneycheck)
instead of "moneycheck" at the error lines (but leave the
Code:
new moneycheck[128]
at its' definition)
__________________
Don't bother to contact me, I'm out of SA-MP
Sascha is offline  
Old 08/06/2010, 04:11 PM   #7
Aleksandar_Zivanovci
Big Clucker
 
Join Date: Apr 2010
Posts: 84
Reputation: 0
Default Re: MySQL query question.

if(IsNumeric(inputtext))
{
if(GetPlayerMoney(playerid) < strval(inputtext))
{
SendClientMessage(playerid, 0xFFFFFF, "You don't have enough cash.");
}
else
{
GivePlayerMoney(playerid, -moneycheck);
new string2[128];
format(string,300,"UPDATE "SQL_FACTION" SET `FactionBank`=FactionBank + %d WHERE `ID`='2'",strval(inputtext));
mysql_query(string);
format(string,128,"You have just deposit %s into HR313SR Faction Bank",inputtext);
SendClientMessage(playerid,COLOR_YELLOW,string2);
}
}
Aleksandar_Zivanovci is offline  
Old 08/06/2010, 04:13 PM   #8
oliverrud
Huge Clucker
 
Join Date: Apr 2009
Location: Denmark
Posts: 415
Reputation: 24
Default Re: MySQL query question.

Aleksander can I ask you one last question? (Thanks Sascha).
oliverrud is offline  
Old 08/06/2010, 05:11 PM   #9
Aleksandar_Zivanovci
Big Clucker
 
Join Date: Apr 2010
Posts: 84
Reputation: 0
Default Re: MySQL query question.

of course
Aleksandar_Zivanovci is offline  
Old 08/06/2010, 05:17 PM   #10
oliverrud
Huge Clucker
 
Join Date: Apr 2009
Location: Denmark
Posts: 415
Reputation: 24
Default Re: MySQL query question.

My first question/problem is,
pawn Code:
if(IsNumeric(inputtext))
        {
            GivePlayerMoney(playerid, strval(inputtext));
        new string2[128];
            format(string,300,"UPDATE "SQL_FACTION" SET `FactionBank`=FactionBank - %d WHERE `ID`='2'",strval(inputtext));
            mysql_query(string);
            format(string2,128,"You have just deposit %s$ into HR313SR Faction Bank",inputtext);
            SendClientMessage(playerid,COLOR_YELLOW,string2);
      }
Let's say theres 500 in the FactionBank.
Right now people can withdraw as much they want so they can actually withdraw 50000 without they loosing anything but the FactionBank money going down.
I want to do so it makes sure the FactionBank money wont go under 0 and that they can't withdraw more then till 0.
Anybody got a solution for this?
oliverrud is offline  
 

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
MySQL Error in the Query? Antonio [G-RP] Help Archive 26 09/09/2010 11:13 AM
MySQL Query Result Reynolds Help Archive 6 08/07/2010 03:04 PM
Error in a MySQL query. Carlton Help Archive 8 16/06/2010 07:53 PM
[MySQL]Need help with a query lauri865 Help Archive 0 19/09/2009 06:36 PM
mysql query. Think Help Archive 3 11/03/2009 06:27 PM


All times are GMT. The time now is 05:36 PM.


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