Forum Moderators: coopster

Message Too Old, No Replies

Multiple MYSQL tables pulling information from each other

possible with PHP?

         

bessington

9:01 pm on Jul 29, 2005 (gmt 0)

10+ Year Member




Is it in anyway possible to write a script that will feed one tables values to another using PHP? This sounds confusing.. I'll use an example:

Say you have a huge product table and one of the fields is for the OS of the product. The OS is set to a number, you could either specify one number for the OS, or multiple (such as 1, 3, 5).

In another table the definitions of those numbers would reside
1 Windows 2000
2 Windows ME
3 Windows XP

etc.

This is written this way so that the FE user can just enter numbers that correspond to the OS - and consequently, the BE person can update what the OS's are and add new ones, etc.

Is this logic crazy? This was an idea from my boss - who seems really psyched about scripting a lot of the definitions of a larger product table this way. (like adding image icon directories for example that are in a smaller table, that the larger product table would pull up from.)

Is this sort of behaviour taxing on the server? What is the easiest way to do something like this?

Thank you!

sned

9:17 pm on Jul 29, 2005 (gmt 0)

10+ Year Member



I believe what you are referring to is a linking table, I'll see if I can give an example ...

Say you have a product table, and in this product table, theres an entry, call it "ourproduct". This entry has an unique key ID of 123.

Then, you have your OS table:
ID: OS
1 : Win98
2 : Win2k
3 : WinXP
4 : Linux
5 : Unix
6 : Mac10
.... etc.

So now you need a way to link these 2 tables - the linking table. So say ourproduct works on all versions of windows, and linux.

Your linking table entries would look something like this:

ProductID : OSID
123 : 1
123 : 2
123 : 3
123 : 4

Then, say you wanted to find out which products support linux, your query would look something like:

SELECT tblproduct.* FROM tblproduct INNER JOIN tbllinkproducttoos ON (tblproduct.ProductID = tbllinkproducttoos.ProductID) WHERE tbllinkproducttoos.OSID = 4

I hope that explains it well enough .. it's simple in my head, but not so simple on paper :)

-sned