• 0

PHP Article Versioning


Question

Okay the problem is as follows. I need to implement article versioning on a site I am building. I need the latest article to also be the one shown on the main page but I also need to be able to view all the old versions of an article.

I have started by always inserting articles into the articles table and never updating them. I have also so made it so the first time I have inserted a new article the version_id of that article becomes equal to the article_id.

I am a bit stuck on what to do now mind. I do understand that every time an insert is done on an existing article I need to make sure that the version_id becomes equal to one.

I am open to any ideas.

Link to comment
https://www.neowin.net/forum/topic/750670-php-article-versioning/
Share on other sites

10 answers to this question

Recommended Posts

  • 0

XML files would be perfect for this. You could allocate one file for all versions of an article and have version numbers and store the latest version number in the row corresponding to the article. That way you will be able to access the most recent version of the article. As you make revisions you can keep adding on new version to the xml file.

  • 0

create a related_to (or something) field with the id of the original article in the article table.

then when doing the select for the listing use the DISTINCT keyword for the related_to field. Just make sure you're sorting by the newest first.

I think that would give you what you want.

Hmm, the more I think about it Original articles would have to have the same value in there related_to and id field.

  • 0

Like +SOOPRcow said, this is actually quite easy to do. You simply do the following:

1. Your articles table should have the following fields included: article_id (Primary Key, Integer), version_number (Integer), version_uid (This is the "related_to" field; it will be the same for all versions of the same article; it simply has to be some unique number or text), and modified_time (DATETIME field)

2. When you create an article, you assign it an article_id, version_number, and version_uid

3. When you edit an article, you create a new article record with a new article_id, you increment the version_number, and then assign the same version_uid as the original article.

  • 0

Just as a caveat: in an ideal relational database system, this would be done with at least 2 tables. One table (articles) would contain the article_id and article_unique_id and other information (such as a BOOLEAN field signaling whether an article is to be displayed or not) while the other table (article_versions) would contain all of the actual article information. The tables would be related to each other by article_unique_id in a one-to-many relationship.

  • 0

This will get the most recent articles by date:

SELECT * FROM articles GROUP BY article_unique_id ORDER BY modified_date DESC

This will get the most recent articles by version:

SELECT * FROM articles GROUP BY article_unique_id ORDER BY version DESC

If that doesn't do what you want, then try this:

SELECT * FROM (SELECT * FROM articles ORDER BY version) GROUP BY article_unique_id

Edited by boogerjones
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Just for anyone reading, AdGuard (the free, standalone MV3 extension) is quite good now, a direct competitor to uBlock Origin Lite and much more built-out than it.
    • Microsoft Edge 149.0.4022.62 by Razvan Serea Microsoft Edge is a super fast and secure web browser from Microsoft. It works on almost any device, including PCs, iPhones and Androids. It keeps you safe online, protects your privacy, and lets you browse the web quickly. You can even use it on all your devices and keep your browsing history and favorites synced up. Built on the same technology as Chrome, Microsoft Edge has additional built-in features like Startup boost and Sleeping tabs, which boost your browsing experience with world class performance and speed that are optimized to work best with Windows. Microsoft Edge security and privacy features such as Microsoft Defender SmartScreen, Password Monitor, InPrivate search, and Kids Mode help keep you and your loved ones protected and secure online. Microsoft Edge has features to keep both you and your family protected. Enable content filters and access activity reports with your Microsoft Family Safety account and experience a kid-friendly web with Kids Mode. The new Microsoft Edge is now compatible with your favorite extensions, so it’s easy to personalize your browsing experience. Download: Microsoft Edge (64-bit) | 193.0 MB (Freeware) Download: Microsoft Edge (32-bit) | 170.0 MB Download: Microsoft Edge (ARM64) | 188.0 MB View: Microsoft Edge Website | Release History Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • Yeah, when I saw that, I wanted to find the nearest nose. You can't find a good nose these days when you need one.
    • Anthropic launches Claude Fable 5, a state-of-the-art AI model that beats OpenAI's GPT-5.5 by Pradeep Viswanathan Back in April, Anthropic announced Claude Mythos Preview, a frontier model with state-of-the-art coding capabilities. Due to the cybersecurity implications that would occur due to the availability of such a powerful model, Anthropic made it available to only a select set of companies around the world. The company's plan was to prepare appropriate guardrails before releasing such a powerful model to everyone. Now, after nearly two months, Anthropic announced Claude Fable 5, its most capable AI model yet for general users. The company also announced Claude Mythos 5, the same underlying model as Fable 5, but with safeguards lifted, making it more suitable for selected cybersecurity and biology use cases. Claude Fable 5 sits a tier above its Opus models and it beats most other generally available models across areas including software engineering, knowledge work, vision, scientific research, and long-running autonomous tasks. To prevent model misuse, when Claude Fable 5 detects certain requests related to cybersecurity, biology, chemistry, or model distillation, the request will be routed to the Claude Opus 4.8 model. Anthropic claims that these safeguards trigger in less than 5% of sessions on average. However, for large organizations working on critical software, Claude Mythos 5 can be availed through Project Glasswing. Later, Anthropic has plans to expand access through a broader trusted access program. As you can notice in the benchmarks above, Fable 5 and Mythos 5 are state-of-the-art on most key AI benchmarks and they are well ahead of OpenAI's frontier model, GPT-5.5. For example, Fable 5 is the new state-of-the-art model for vision tasks. Also, Mythos 5 has the strongest cybersecurity capabilities of any model in the world. Claude Fable 5 and Claude Mythos 5 are priced at $10 per million input tokens and $50 per million output tokens, which is less than half the price of Claude Mythos Preview. Another big change is that Anthropic is making a change to the way they handle business customer data for both Fable 5 and Mythos 5 models. The company will now require 30-day retention for all traffic on both first- and third-party surfaces. Anthropic promises that it won't use the data to train Claude models, instead it will use it against complex and novel attacks. Claude Fable 5 is available today on the Claude API and consumption-based Enterprise plans. It is also included at no extra cost for Pro, Max, Team, and seat-based Enterprise customers from today through June 22. After that, users on those plans will need usage credits to continue using Fable 5, unless Anthropic extends the included access window based on capacity. Developers can access Fable 5 through the Claude API using the claude-fable-5 model name.
  • Recent Achievements

    • Week One Done
      rubentuben8 earned a badge
      Week One Done
    • Week One Done
      ARaclen earned a badge
      Week One Done
    • One Year In
      jojodbn earned a badge
      One Year In
    • One Month Later
      jojodbn earned a badge
      One Month Later
    • Week One Done
      jojodbn earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      530
    2. 2
      PsYcHoKiLLa
      234
    3. 3
      +Edouard
      128
    4. 4
      ATLien_0
      88
    5. 5
      Steven P.
      83
  • Tell a friend

    Love Neowin? Tell a friend!