Jump to content

PHP Versioning


gazza52

Recommended Posts

Hi All,

 

I'm trying to produce a very basic Wiki like feature where you can view an article and then click on say a history link and view the recent changes which have taken place and also roll back to old articles.

 

These articles will simply be Mysql record entries.

 

Please can you assist as I am struggling to find examples of this?

 

Thanks

 

Gary

Link to comment
Share on other sites

you need to save every full version of the document in the mysql table.

 

When you want to check to see what lines are different, you just loop through line by line and compare differences between the lines.

- If document A has less lines then document B, then lines were added to get you to B

- If document A has more lines then document B, then lines were removed to get you to B

Link to comment
Share on other sites

Hi, thanks for your reply.

 

As its only one article I would be comparing the versions for would it be adviseable to have just one table with different versions of the article and then compare the date it was added so this would then show different versions of edit of the document.

 

I would also tho like to roll back to a previous version of the article I dont think the above method would help?

Link to comment
Share on other sites

What I posted would work, since you are save the FULL version of EVERY change.

 

First entry into the database

First entry

 

Second entry into the database

First entry
Another line
Another line
Another line

 

Third entry into the database

First entry
Another line
Another line

 

 

lets say your at entry 3, and you want to roll back to entry 2, you would then grab that entry from the database, this would then become entry 4, and the table would look like this:

 

First entry into the database

First entry

 

Second entry into the database

First entry
Another line
Another line
Another line

 

Third entry into the database

First entry
Another line
Another line

 

Fourth entry into the database

First entry
Another line
Another line
Another line

 

You should be able to see that entry 4 and entry 2 are the exact same thing..

Link to comment
Share on other sites

I am new to PHP so please forgive me lol.

 

My understanding is I will have a table called articles

 

Article ID/Article Title/Contents/Date Added

 

If i inserted this table in I can obviously have my article in but if I amended it it will delete the previous contents. How do i ammend contents so the previous contents are stored and the version saved?

Link to comment
Share on other sites

With article id as an auto increment field, and date added as a timestamp (on insert):

mysql_query("INSERT INTO table (title, contents) VALUES ('Article Name', 'This is the first insert')");

mysql_query("INSERT INTO table (title, contents) VALUES ('Article Name', 'This is the first insert, with modification')");

mysql_query("INSERT INTO table (title, contents) VALUES ('Article Name Modified Title', 'This is the first insert')");

 

This will insert 3 rows into your database, the last row, will be the most current version.

so, to select the most current version you want, you just load the last row in the table:

 

mysql_query("SELECT * FROM table ORDER BY id DESC LIMIT 1");

Link to comment
Share on other sites

I understand how this would work for comparing one article but what about if I wanted to have 3 articles in there?

 

It wouldnt work as the ID would be 1/2/3 etc for article 1 with changes made and then 4/5/6 for article 2 so when comparing say article 1 I would have article 2 in there aswell.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.