whi01135879 Posted October 28, 2010 Share Posted October 28, 2010 Hi everyone, im new to php, iv just created a news feed where i have a limit of 10 to be echoed out. but i want the update form to delete the oldest post as it updates... how would i do this please : Link to comment https://forums.phpfreaks.com/topic/217129-delete-oldest-row/ Share on other sites More sharing options...
whi01135879 Posted October 28, 2010 Author Share Posted October 28, 2010 <?php if($_POST['submit']) { $title = trim(stripslashes($_POST['title'])); $news = stripslashes(nl2br($_POST['news'])); if($title&&$news){ require_once("../inc/connect_to_mysql.php"); $dateof = date("Y-m-d"); $insert = mysql_query("INSERT INTO newsfeed VALUES ('','$title','$news','$dateof')"); die ('<p class="accepted">Your news has been posted</p>'); } else{ $msg_to_user = '<p class="error">Please fill out the title and news update to procced.</p>'; } } ?> Link to comment https://forums.phpfreaks.com/topic/217129-delete-oldest-row/#findComment-1127678 Share on other sites More sharing options...
Andy-H Posted October 28, 2010 Share Posted October 28, 2010 <?php if($_POST['submit']) { $title = trim(stripslashes($_POST['title'])); $news = stripslashes(nl2br($_POST['news'])); if($title&&$news){ require_once("../inc/connect_to_mysql.php"); $dateof = date("Y-m-d H:i:s"); $insert = mysql_query("INSERT INTO newsfeed VALUES ('','$title','$news','$dateof')"); $delete = mysql_query("DELETE FROM newsfeed ORDER BY dateField DESC LIMIT 1"); die ('<p class="accepted">Your news has been posted</p>'); } else{ $msg_to_user = '<p class="error">Please fill out the title and news update to procced.</p>'; } } ?> Link to comment https://forums.phpfreaks.com/topic/217129-delete-oldest-row/#findComment-1127689 Share on other sites More sharing options...
whi01135879 Posted October 28, 2010 Author Share Posted October 28, 2010 Sweet just changed that code now works ace :P <?php if($_POST['submit']) { $title = trim(stripslashes($_POST['title'])); $news = stripslashes(nl2br($_POST['news'])); if($title&&$news) { require_once("../inc/connect_to_mysql.php"); $dateof = date("Y-m-d"); $insert = mysql_query("INSERT INTO newsfeed VALUES ('','$title','$news','$dateof')"); $delete = mysql_query("DELETE FROM newsfeed ORDER BY ID LIMIT 1"); die ('<p class="accepted">Your news has been posted</p>'); } else{ $msg_to_user = '<p class="error">Please fill out the title and news update to procced.</p>'; } } ?> Link to comment https://forums.phpfreaks.com/topic/217129-delete-oldest-row/#findComment-1127696 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.