Jump to content

[SOLVED] How to : User Item Count


gizmoman

Recommended Posts

Hi, i am new to MySQL and i am trying to make a simple online game. I searched the web about my problem about 1 hour and nothing found. May be it's about my little english huh  Let me ask what i am trying to do. And i dont have any idea about that.

 

I have an item table that has about 50 items. And a user table. What i want to do is inserting database how many and which item does a user have. Like "A user has 35 item B", "A user have 20 item C" and so... I thought about it some and i just found creating fields for EVERY item on user table and insert the items count on there. And this would be so much effort for mysql i think. Any other suggestion to do that easier please? I bet there is but i dunno yet Thanks...

Link to comment
Share on other sites

I think something like this may work.

 

Users table

user_id | user_name

--------------------

1        | Some Name

2        | Some other name

 

Users Items table

item_id | user_id

----------------

1        | 1       

1        | 1

 

Items table

item_id | item_name

-------------------

1        | A

2        | B

3        | C

 

select count( i.item_id ) from Items i left join Users u on i.user_id = u.user_id where u.user_id = 1 group by i.user_id;

 

Or something like that.

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.