Jump to content

One to many relationship. Tricky for me


figo2476

Recommended Posts

Hi:

 

Wordpress offers extra fields, so I follow its idea and create 2 tables

 

Editions table:

id name

1  edition1

2  edition2

 

Extra field table:

(Extend the table above. Offer customized fields, for different projects needs)

edition_id key    value

1          venue  city

1          state  abc

1          club  A

2          venue  city_2       

2          state  bbb

2          club  B

 

I want to group those fields, so I can get something like

id name      venue  state club

1  edition1  city  abc  A

 

It may not be possible, but the idea is able to group information. any hint?

Link to comment
https://forums.phpfreaks.com/topic/103109-one-to-many-relationship-tricky-for-me/
Share on other sites

Your query will likely have to look something like this:

<?php
$tableName="extra";
$sql="select 
	a.edition_id as id, 
	d.name, 
	a.value as venue, 
	b.value as state, 
	c.value as club
from $tableName a, $tableName b, $tableName c, editions d
where a.edition_id=b.edition_id
and c.edition_id=b.edition_id
and d.id=a.edition_id
and a.key='venue'
and b.key='state'
and c.key='club';";
?>

 

If, however, your table looked like this:

extras:
edition_id | venue | state | club
1          | city  | abc   | A
2          | city_2| bbb   | B 

Then the query would be much simpler to create. If you are not planning on having different amounts of extra information for each edition then it may be better to go this way.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.