Page 1 of 1
Joining tables i think
Posted: Sun Feb 21, 2010 9:20 pm
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?
Re: Joining tables i think
Posted: Sun Feb 21, 2010 9:34 pm
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
Re: Joining tables i think
Posted: Sun Feb 21, 2010 9:50 pm
by Da_Elf
with 3 tables wont that make it harder to join?
Re: Joining tables i think
Posted: Sun Feb 21, 2010 10:02 pm
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
Re: Joining tables i think
Posted: Mon Feb 22, 2010 7:11 am
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
Re: Joining tables i think
Posted: Mon Feb 22, 2010 9:52 am
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"
but if your solution work for you is fine
Miko