katl Posted May 9, 2007 Share Posted May 9, 2007 Is there a way I can limit the number of records that are stored in a database? I am using a PHP guestbook script for personal use and only want to save say the last 100 messages. Thanks! Link to comment https://forums.phpfreaks.com/topic/50688-limiting-number-of-records-stored-in-database/ Share on other sites More sharing options...
per1os Posted May 9, 2007 Share Posted May 9, 2007 Best way is to do a count before insertion. IE: <?php $count = mysql_fetch_assoc(mysql_query("SELECT count(gbid) count FROM guest_book;")); $count = $count['count']; if ($count > 100) { mysql_query("DELETE FROM guest_book ORDER BY dateentered LIMIT 1;"); } ?> Note unsure if it works correctly test it on a dev machine before using it in production. Link to comment https://forums.phpfreaks.com/topic/50688-limiting-number-of-records-stored-in-database/#findComment-249180 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.