Link to home
Start Free TrialLog in
Avatar of Puneet Arora
Puneet AroraFlag for India

asked on

How to display n -n relationship in php : Many to many relationship

If I have following tables


Many to many relationship

Category A
ID , CategoryName

CategoryB


ID_CategorB , FK_CategoryA, CategoryName


Third Table Relationship Table

Relation
ID ,ID_CategoryB

How can I show the values in "select "  box
Avatar of Mike Eghtebas
Mike Eghtebas
Flag of United States of America image

Table_CategoryA
ID_A     -- PK
CategoryName

Table_CategoryB
ID_B     -- PK
CategoryName

Table_A_B      <-- this is known as bridge table
ID_A     -- FK
ID_B     -- FK


You can make write SQLs you need from these table like:

Select a.CategoryName as Cat_A, b.CategoryName As Cat_B
From Table_CategoryA a inner join Table_A_B ab
on a.ID_A = ab.ID_A inner join Table_CategoryB b
on ab.ID_B = b.ID_B

Open in new window

Avatar of Puneet Arora

ASKER

Thanks for the reply :

I want   to show it in select box , then uses these multiple values
to select some more in the Category  C table , In php do I need to simply use for loop
to get all the values  and show in "select option box " and use java script to transfer
it to input box with multiple values ? Question is How to ?
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial