Jump to content

Recommended Posts

i have 2 tables, items and users.

item has => item_id(unique_1), item_describe,item_cost,item_unit_price

user => user_name, psws, last_name

 

so whenever user logins inside and adds a item, i want to connect that adding of items with the user.

 

may b looks simple, but i want to do it without adding any extra field in tables.. is that possible.. Or else if i make item_id as primary, then how should i proceed?

 

 

And if item_id is not unique, if 2 users have same items addition with same id,cost_price, how could that be achieved?? thnks in advance...

Link to comment
https://forums.phpfreaks.com/topic/273956-php-mysql-connect-2-tables/
Share on other sites

CREATE TABLE useritem (
user_id INT,
item_id INT,
PRIMARY KEY(user_id, item_id)
)

 

if an item can be owned by one or more users and users can have one or more items then you use a link table to reconcile the many to many relationship

Edited by Barand
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.