Hello!
I develop at the moment an online based cycling manager!
I have a problem in the programming right know.
I want that every user have x points when they start
and can buy athletes for the points but i have some trouble.
I have two questions i want help with:
ONE: witch tables in the mysql would i choose? example if i buy one athlete,
the athlete adds in a seperate table "athlete" with the columns "id, athlete, user or
in the user table? please help me with a code snippet in php and mysql how i can do that.
TWO: when i buy one athlete the points get lower. Example. i have 1000points at start and
after buy one athlete for 120 points the points would be 880. I have test it with sql syntax UPDATE but i got the error
example if i buy ten athletes who cost 110 each it would be over 1000 points but the points get: -100 but i want the stay on 0 points
not -100. Please help me with code snippets in php how i can do that!
Please help me with my two problems!
/Johan
help with mysql!
Moderator: General Moderators
Re: help with mysql!
ONE: The users table contains USER data; the athletes table contains ATHLETES data. Don't put data that belongs to one in the other. You probably have a many-to-many relationship between the tables (a user may have "many" athletes, the athletes may have "many" users, yes?). That requires a 3rd table to join each user records to each of his athlete records. If this concept is not clear to you, you should read about relational databases before going any further.
TWO: Just check the points balance against what the user asks to buy, BEFORE processing the user request. If he tries to buy more than his balance, DON'T process the request, notify the user that he doesn't have enough points.
TWO: Just check the points balance against what the user asks to buy, BEFORE processing the user request. If he tries to buy more than his balance, DON'T process the request, notify the user that he doesn't have enough points.
Re: help with mysql!
califdon wrote:ONE: The users table contains USER data; the athletes table contains ATHLETES data. Don't put data that belongs to one in the other. You probably have a many-to-many relationship between the tables (a user may have "many" athletes, the athletes may have "many" users, yes?). That requires a 3rd table to join each user records to each of his athlete records. If this concept is not clear to you, you should read about relational databases before going any further.
TWO: Just check the points balance against what the user asks to buy, BEFORE processing the user request. If he tries to buy more than his balance, DON'T process the request, notify the user that he doesn't have enough points.
Thanks for the help! i think i have understand number one. I create example three tables "users" "athletes" and "transactions" and they all have
relations in the database!
But number two can you help me with a php example how i can do that?