TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   MySQL & Databases (http://www.talkphp.com/mysql-databases/)
-   -   mysql update (http://www.talkphp.com/mysql-databases/5111-mysql-update.html)

sils 11-13-2009 06:42 PM

mysql update
 
I'm basicly working with mysql update here.

So i have a table called users and a field named money.
now when user register he also register's an amount of hidden input of money.
input sent to mysql table>money(field)>amount.

now what i want is that if he presses a button, it will decrease his amount of money in the sql.and the button he press will give him something like 500$ for a candy.
so to a field named candy the update will make it (1) and money from the basic amount will get decreased.

can someone help me make the code?

maeltar 12-04-2009 07:17 AM

Ok, been a while since you posted but will give you some pointers...

Break the problem down into manageable pieces, work out the logic first..

We will take it as read that the data is already in the DB..

So logic would be something like...

Get current "money" from DB

Decrease current "money" by "cost of item"

Update new balance in DB

Update/create entry for "item purchased"


Now I would point out at this stage that now it's written out a possible issue can be seen...

You have no way of tracking purchases..

So to that end, you would need another table which you would write the purchases (spelling) into, giving you the ability to track customer purchases.

So, you would have 2 tables....

1/ money, with a unique ID for each customer.

2/ purchases, with a fields holding the customer ID, Item Purchased, Cost, date/time

Anyway thats some thoughts for you if you decide to come back and have a look....


All times are GMT. The time now is 12:21 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0