Forum Moderators: open

Message Too Old, No Replies

putting a table into a table in mySQL

         

marsman2015

11:14 pm on Nov 19, 2007 (gmt 0)

10+ Year Member



Hey, I'm new to mySQL and I am working something that would be a lot easier if it were possible to insert one table into a spot on another table.. Is this possible? How would I go about doing it?

Thanks

LifeinAsia

11:19 pm on Nov 19, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



My guess is that trying to do that would actually NOT make things easier, if it were possible. Perhaps if you gave us a little more information about what you're trying to accomplish?

Oh, and welcome to Webmaster World!

marsman2015

11:27 pm on Nov 19, 2007 (gmt 0)

10+ Year Member



thanks for the welcome :)

And I am working on a site similar to ratemyprofessor.com / ratemyteacher.com however it is just for my fraternity.. why they cant use the regular one I don't know, but they have asked me to make one.. so anyways, if you don't know, its a website where you leave comments about a different professors and give them ratings and such. What I was thinking would be to create a table with all the professors names in one column, then in a second column, have it be filled with tables with all their ratings and comments and such, so when looking at a professors page it would be easy to find the name and pull up all the things about that specific person. Am I trying to go about this the wrong way?

Thanks

LifeinAsia

12:05 am on Nov 20, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Right logical thinking, wrong implementation. :)

What you want to do is have a separate table for the reviews and join the data when you output the page.

Quick example:
Prof_table-
ProfID ¦ ProfName
1 ¦ Dr. Jekyll
2 ¦ Mr. Hyde
3 ¦ Dean Wormer

Review_table-
ReviewID ¦ ProfID ¦ ReviewText
1 ¦ 1 ¦ Has some identity problems...
2 ¦ 2 ¦ What a monster!
3 ¦ 3 ¦ Put HIM on double-secret probation!
4 ¦ 3 ¦ Has a friendly wife.

Now let's say you want to display the information for Dean Wormer. Your query would look something like:

SELECT Prof_table.ProfName, Review_table.ReviewText
FROM Prof_table, Review_table
WHERE Prof_table.ProfID=Review_table.ProfID

marsman2015

11:52 pm on Nov 20, 2007 (gmt 0)

10+ Year Member



Wow- it took me a while to make it work but I think I've finally got the concept working.. now I just need to make everything else heh.

Thanks a lot for the idea and help!