Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
Like Tree1Likes
  • 1 Post By mlseim

Thread: Variable number of texts with headlines. Best way to store?

  1. #1
    Junior Member
    Join Date
    Jun 2015
    Posts
    13
    Member #
    50223

    Variable number of texts with headlines. Best way to store?

    Hello. On my website a users will review music by other users. When the user adds their song they pick up to 3 headings that they want to be listed when someone else reviews their song. For example I might have a song and choose the headings "Production", "Melody", "Lyrics", when someone else goes to review this song they will see those headings above text areas where they fill it it and leave the appropriate feedback. There will always be an 'overall' section that will be added automatically. The important part is that the number of review headings can vary, but at the moment a maximum of 3.

    I have a few ideas on how to do this, and I'm not sure which is best.

    1. I was just going to have a table called 'reviews' that would contain these column names: 'review_heading_1', 'review_content_1', 'review_heading_2', 'review_content_2, 'review_heading_3', 'review_content_3', 'overall_content'. (as well as the id's for song ect)

    But that seems bad to me. What if the owner of the song only wants one heading? Then there will be a total waste of space with empty texts?

    2. I could keep all the review headings and content in one text field, and add my own symbols so I can separate the data later. For example, around the headings I could put {{}}, then use regex to split them later.

    3. I could have two tables for the reviews. One that contains it's id, and user id ect, and one that's just for review headings, review content. But that would mean a table join. I'm starting to think this is the best way.

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,662
    Member #
    5580
    Liked
    713 times
    Go ahead and put them all in that one table. Use PHP to dynamically generate the page with the text boxes, where it only will display a textbox if there is a heading, otherwise it won't show. Test if the heading is empty (blank) or not.
    brandMatt likes this.


  4. #3
    Senior Member brandMatt's Avatar
    Join Date
    Oct 2015
    Location
    St .Catharines Ontario
    Posts
    240
    Member #
    52164
    Liked
    51 times
    mlseim has the right idea, if I am understanding correctly. Single tables make sense. I would have a single table for 'review_heading', then a second table for 'review_content'. Piling all the data in a single table seems clumsy to me, trying to add all that data to single fields seems even more clumsy. One table for each data type would result in less wasted space.

  5. #4
    Senior Member sarahswansea's Avatar
    Join Date
    Oct 2015
    Location
    Swansea, UK
    Posts
    149
    Member #
    52184
    Liked
    64 times
    Option 3 Option 3 Option 3 Option 3!!!

    Song Table
    id | title | genre
    primary key id

    Headings Table
    song_id | heading_name
    composite unique / primary key (song_id, heading_name)
    index(song_id)

    Review Table
    song_id | heading_name | reviewer_user_id | review_text
    composite foreign key (song_id, heading_name) references headings table
    composite unique / primary key (song_id, heading_name, user_id)
    index (song_id, heading_name)
    index (user_id)


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 11:57 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com