Making compatibility charts in MySQL

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
bwv2
Forum Commoner
Posts: 83
Joined: Fri Jun 10, 2005 11:50 am
Location: AZ

Making compatibility charts in MySQL

Post by bwv2 »

I'm sort of new to databases and mySQL, but until now I've been able to find my way through it. Now I'm trying to make a compatibility chart of some kind in mySQL and I'm at a loss.

I would like to be able to find out which "widgets" are compatible with which "gadgets" that are for sale on my website. If a customer chooses a certain widget, the PHP script will automatically generate a list of compatible gadgets. In Excel, this would look like a matrix with Widgets across the top, and Gadgets down the side. Then there would be a series of x's in the matrix to show compatibility. How can I do this in mySQL?

I guess one way I could do it would be to actually make a table whose column names are Widgets and whose row names are Gadgets, then I could have an "x" at the intersection of each row/col that are compatible with one another. It just seems that there might be a cleaner way. As it stands, I have a table full of Widgets and a table full of Gadgets, each containing certain specifications. Is there any way I could somehow link compatibility between these tables? If not, I could certainly do it the way I described above. Let me know if you have any ideas. Thanks.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

A table of widgets, gadgets, and one that references a widget and gadget, which will tell you they are compatible. This is called a many-to-many relationship for your information.
Post Reply