Hello Php Forums!

I have a script that has point system. and if you have enough points you can get rewards example
usb,tshirts etc..

i already done the function when the user redeem his/her points will be deducted based on how much points is needed to redeem that item.
now i have a problem,

i want to display the redeem items name on his/her profile page.
how can i do it?

EXAMPLE STRUCTURE OF THE TABLES:
rewards
rewardid | rewardname | price

   1 |     USB    | 10

USERS
userid | username | points | password |redeemed

1  | code     | 500    | 441$!sf  | ?????

THANKS!

Recommended Answers

All 6 Replies

Member Avatar for diafol

Have a separate related user_rewards table:

ur_id (PK/int)
reward_id (FK/int)
user_id (FK/int)
dated (datetime or int)

Depending on the table type InnoDB / MyISAM etc and the MySQL version, you can force Foreign Key (FK) contraints.

I have InnoDB and the Latest MySQL version.

can i know the exact or even just a pinch of php code needed for it to display? the rewards redeemed.

Thanks

hello i already setup the sql table and added a sample data to it.

user_rewards

urid |  reward_id |  user_id |

  1         1           1

i want to display the name of the reward with the id = 1,
example:

reward_id | reward_name |
   1           USB

I want to display the USB as a redeem item on the profile page.

whats the exact mysql/mysqli query for that?

THANKS!

Member Avatar for diafol

whats the exact mysql/mysqli query for that?

This is beginning to sound like a "gimme post". Really, it's your job to build the query and see if it works. If not, we can look at it for you. I'll give you some pointers though...

SELECT table1.fieldA, table2.FieldZ FROM table1 INNER JOIN table2 ON table1.fieldB = table2.fieldY WHERE table1.fieldC = 'somevalue'

You can build up from 2 tables to 3, 4, 5, etc just be adding..

INNER JOIN table3 ON table2.fieldC = table3.fieldX ...

Note that the WHERE clause needs to go on the end in this case.

Hello i really dont know anything about query, i just started learning php and mysql this week so i really dont understand , i only know about insert,delete,update JOIN. not yet :(

so please? give examples?

Member Avatar for diafol

so please? give examples?

I just did. Do your own research please. We don't see the point in copying examples from the internet and posting them here.

i just started learning php and mysql this week

Learning is most effective when you've done the work yourself. Find some examples, try to build your own query. If you get stuck, post back with the query and the issue.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.