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!

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.