bassplaya4string Posted April 25, 2008 Share Posted April 25, 2008 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! Quote Link to comment Share on other sites More sharing options...
Fadion Posted April 25, 2008 Share Posted April 25, 2008 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. Quote Link to comment Share on other sites More sharing options...
bassplaya4string Posted April 25, 2008 Author Share Posted April 25, 2008 Thanks a lot for the advise!!! I like the idea of keep it separate from the main table. Can someone give me an example on how to copy the data to the archive table before deleting it from the main table? Quote Link to comment Share on other sites More sharing options...
Fadion Posted April 25, 2008 Share Posted April 25, 2008 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. Quote Link to comment Share on other sites More sharing options...
bassplaya4string Posted April 26, 2008 Author Share Posted April 26, 2008 GuiltyGear, you are the man! Thanks a lot for the help! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.