Single cell Multiple records?

Discussion in 'MySQL' started by shubhamjain, Dec 13, 2009.

  1. #1
    I have some text which has to edited by visitors. Now i want to store the previous non edited text as well as the new one. Now I have many such texts like these which have to be edited. Eg.

    Table - Text
    
    Id             Text
    1              Hi this is a text
    2              Hi this is another text
    Code (markup):
    A visitor comes and edits text 1 now i want to store "Hi this is a text" as well as the new edited text.

    One solution may be to alter table to create new columns every time text has been edited but this doesnt seem to be a good programming practice any solution to this?
     
    shubhamjain, Dec 13, 2009 IP
  2. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #2
    Does it have a special purpose to store older text?

    I see following 2 solutions as feasible one.
    1. You can create another table for storing all previous text edits.
    2. You can create another column if separate table is not what you need. Store all previous edited text in that column in form of XML :)
     
    mastermunj, Dec 13, 2009 IP
  3. shubhamjain

    shubhamjain Active Member

    Messages:
    215
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    63
    #3
    Thanks for XML advice. Will surely Try.
     
    shubhamjain, Dec 13, 2009 IP
  4. plog

    plog Peon

    Messages:
    298
    Likes Received:
    11
    Best Answers:
    1
    Trophy Points:
    0
    #4
    No, option 3 is the right way to go--neither add a new table nor store xml data in a new column (which is the wrongest way of doing things).

    You should reconfigure your Text table to include either a date stamp column or some sort of numerical incrementing system so you know when each Text was added. Here's how your table should look:

    
    exid          datetextadd                text
    1              12/1/2009                  Hi this is a text
    2              12/1/2009                  Hi this is another text           
    1              12/14/2009                This text replaces the first one
    
    PHP:
    exid is the id of another table which links to the text. To pull the most recent text for an external id you would order by the datetextadd field in descending order and limit by one.
     
    plog, Dec 14, 2009 IP
  5. mastermunj

    mastermunj Well-Known Member

    Messages:
    687
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    110
    #5
    @plog, your solution is feasible provided table has only id and text field, but if table has several other fields, creating another table is a wise decision.

    xml solution is given considering if he wants to store only 2 - 3 or 5 latest modifications.


    @shubhamjain, plog's solution seems appealing and you should give it a try. more over, we are always here if you are stuck up somewhere :)
     
    mastermunj, Dec 14, 2009 IP