Jump to content

Insert from 1 table to 2 tables


nagrap

Recommended Posts

Hi,

 

I'm quite new to php and not the greatest of coders, so urgently require your help.

 

I want to be able to take data from an un-normalised table and load into 2 normalised tables as below:

 

1) Table 1 - All Music Tracks (Un-normalised table)

 

Album Name

Artist Name

Track Name

Track Length

etc.

 

2) Table 2 - Albums Table (Normalised table)

 

ID

Artist Name

Album Name

etc.

 

3) Table 3 - Tracks Table (Normalised table)

 

ID

Track Name

Album ID (foreign key to Albums table)

etc.

 

Can someone please provide some sample code as a starting point? The All Music Tracks table includes both the album name and track name in each row, but I only want the album appearing once in the Albums tables, would I have to do an Distinct select first to get the album names into an array? I'm not sure how I would then have  nested loop to do the insert into the Tracks table.

 

Much Appreciated,

 

PD

Link to comment
https://forums.phpfreaks.com/topic/222130-insert-from-1-table-to-2-tables/
Share on other sites

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.