close ad
Install the LAtest Updates to Work with CC 2017 and CC 2018
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

PHP MYSQL Form - Multiple Select List

Thread began 12/30/2009 2:51 pm by karen.marley367377 | Last modified 5/03/2011 4:03 pm by karen.marley367377 | 18751 views | 29 replies

Jason ByrnesWebAssist

I'm not really sure what feature you are referring to in MySQL.

A linking table is not so much a mySQL Feature as a common concept in Relational Database design.


the concept of a linking table is to use a third intermediary table to create a many to many relationship between to data tables.

In your case, you have users and categories, and you are trying to create a many to many relationship between them.

in other words, all users can relate to any of the available categories.

to do this you create a linking table.

the linking table creates the relationship be creating a record for each category the user should belong to.

I'll try to illustrate using sample data.

the table structure would be:

users:
userID - Primary Key Column
userName - text
etc

categories:
catID -Primary Key
catName -text

userCategories
usercatID -Primary key
usercatUserID relates to users.userID
usercatCatID - relates to categories.catID

table data:

users:
userID | userName | etc....
-------+------------+
1 | Tom |
-------+------------+
1 | John |
-------+------------+
1 | Adam |
-------+------------+


categories:
catID | catName |
------+-----------+
1 | Fruit |
------+-----------+
2 | Vegitable |
------+-----------+
3 | Meat |
------+-----------+
4 | seafood |
------+-----------+



Now, to assign Tom (userID = 1) to the Vegetable (catID = 2), Meat (catID = 3) and Seafood (catID = 4) Group, we would creat the folloing records in the userCategories table:

userCategories
usercatID | usercatUserID | usercatCatID |
----------+---------------+--------------+
1 | 1 | 2 |
----------+---------------+--------------+
2 | 1 | 3 |
----------+---------------+--------------+
3 | 1 | 4 |
----------+---------------+--------------+




to assign adam (userID = 3) to the Fruit (catID = 1), and vegitable (catID = 2) group:

userCategories
usercatID | usercatUserID | usercatCatID |
----------+---------------+--------------+
4 | 3 | 1 |
----------+---------------+--------------+
5 | 3 | 2 |
----------+---------------+--------------+



and to assign John (userID = 2) to the Meat (catID = 3), and Seafood (catID = 4 group:

userCategories
usercatID | usercatUserID | usercatCatID |
----------+---------------+--------------+
6 | 2 | 3 |
----------+---------------+--------------+
7 | 2 | 4 |
----------+---------------+--------------+

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...