Joining tables i think

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Da_Elf
Forum Commoner
Posts: 81
Joined: Mon Dec 29, 2008 12:31 pm

Joining tables i think

Post by Da_Elf »

Ok im not sure what to do here. i dont know if joining tables will work. Ive got 1 table which is called "Days" its got dayID, DayName and BandID. then ive got a table called "Bands" with BandID, BandName, BandDescription. the days is just filled with Sunday to Saturday and every week that table is updated to change what band from a pool of bands will be playing that week. i just need to create a html table which pulls the days name out of the days table then checks the bandid then inserts into the html table the band name and description. whats the best way to do this?
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: Joining tables i think

Post by mikosiko »

yes, join between the 2 tables will work... the easy way: create a view in the database joining the 2 tables and in you php/html just make reference to the view.

In another note, your model could be improved if you have 3 tables instead of 2.
Table Days:
DayId
DayName

Table Bands:
BandId
BandName
BandDescription

Table DaysBands: (This table represent the relation between a day and the band(s) playing any given day)
DayId
BandId

Hope this help
Miko
Da_Elf
Forum Commoner
Posts: 81
Joined: Mon Dec 29, 2008 12:31 pm

Re: Joining tables i think

Post by Da_Elf »

with 3 tables wont that make it harder to join?
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: Joining tables i think

Post by mikosiko »

Da_Elf wrote:with 3 tables wont that make it harder to join?
just a little... but your business model will improve... in your original model per example you can have more than one band playing the same day, but the DayName need be duplicated in your table Days (with different IDs).. in the second model with 3 tables the Days are present only one time, hence give you more clarity and flexibility and save space in you database.

Your model is small and probably you can live with the way that you are implementing it... but in bigger systems/models where you manage thousands of records the space and your model flexibility is important.

Miko
Da_Elf
Forum Commoner
Posts: 81
Joined: Mon Dec 29, 2008 12:31 pm

Re: Joining tables i think

Post by Da_Elf »

actually i didnt need to do any joining. all i needed to do was use

Code: Select all

"Select * From Days Order By DayID ";
then in the "while" loop i just pulled band id from the Days table and used it in another seach

Code: Select all

$bid = $row['BandID'];
"Select * From Bands WHERE BandID = '$bid' ";
then used that search to pull up the band info then close the loop
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: Joining tables i think

Post by mikosiko »

Da_Elf wrote:Ok im not sure what to do here........... whats the best way to do this?
it works... maybe I did read your original post wrongly... I understood that you were asking for "the best way to do this" :roll:

but if your solution work for you is fine :wink:
Miko
Post Reply