Jump to content

Best way to make an archive with MySQL & PHP


bassplaya4string

Recommended Posts

I am making a site that uses a while loop to fetch all of the entries that have been posted in a MySQL database. I have a script that removes the entries, but it deletes them from the database. What is the best way to remove the entry from the main list, but not have it deleted from the DB. My ultimate goal is to create a page called archives.php and have all of the posts from the main list that have been removed shown there. Any help/ideas would be greatly appreciated!

Link to comment
Share on other sites

The best way would be having a archive table. When u run the queries and specify which entry is old (by date or whatever), copy that record to the archive table and delete it from the main table. Or just add an archive column to the main table which is flagged as true when the entry needs to be archived.

Link to comment
Share on other sites

Im showing the simplest approach as im no mysql expert. The procedure is copy data into variables, delete old row and insert the new one:

 

<?php
$resultsEntries = mysql_query("SELECT * FROM entries WHERE ....."); //.... = your where clause
while($valuesEntries = mysql_fetch_array($resultsEntries)){
    $title = $valuesEntries['title'];
    $description = $valuesEntries['description'];
    $id = $valuesEntries['id'];
    $resultsDelete = mysql_query("DELETE FROM entries WHERE id=$id");
    $resultsUpdate = mysql_query("INSERT INTO entries (title, description) VALUES ('$title', '$description')");
}
?>

 

As i said this is te easiest method i can think of, but maybe there is any mysql trick (that im not aware of) that can make the work faster and better.

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.