mike12255 Posted January 23, 2009 Share Posted January 23, 2009 I have a database, that only contains 4 things inside it. Is there a way that when i go to add a new entry to it, searches for the oldest entry in 'headernews' and deleates it? Quote Link to comment https://forums.phpfreaks.com/topic/142099-solved-deleting-oldest-entery/ Share on other sites More sharing options...
gevans Posted January 23, 2009 Share Posted January 23, 2009 Can you show us your database? field names... Quote Link to comment https://forums.phpfreaks.com/topic/142099-solved-deleting-oldest-entery/#findComment-744193 Share on other sites More sharing options...
revraz Posted January 23, 2009 Share Posted January 23, 2009 How do you determine the oldest entry? Is there a date field? Quote Link to comment https://forums.phpfreaks.com/topic/142099-solved-deleting-oldest-entery/#findComment-744222 Share on other sites More sharing options...
Adam Posted January 23, 2009 Share Posted January 23, 2009 If you have a field which has an auto_incrementing value, you could use something like: Â DELETE FROM table_name ORDER BY field_name ASC LIMIT 1; Â This may well work in other situations but I've not tested! Also it doesn't necessarily need to be an auto_incrementing field, just an ASCending (or DESCending) pattern that you can rely on to be in order of old to new (or new to old). Â Adam Quote Link to comment https://forums.phpfreaks.com/topic/142099-solved-deleting-oldest-entery/#findComment-744283 Share on other sites More sharing options...
mike12255 Posted January 23, 2009 Author Share Posted January 23, 2009 sorry, just wrote an exam and school and got back, so lets say that the database looked like below, probually wont but something similar: Â you guys say theres a way to deleate it using the date? Â btw idk if that is setup right im not the best in mysql Quote Link to comment https://forums.phpfreaks.com/topic/142099-solved-deleting-oldest-entery/#findComment-744342 Share on other sites More sharing options...
revraz Posted January 23, 2009 Share Posted January 23, 2009 Sure, just order by date. Quote Link to comment https://forums.phpfreaks.com/topic/142099-solved-deleting-oldest-entery/#findComment-744361 Share on other sites More sharing options...
mike12255 Posted January 23, 2009 Author Share Posted January 23, 2009 ok, so would that put oldest as first or as last? Quote Link to comment https://forums.phpfreaks.com/topic/142099-solved-deleting-oldest-entery/#findComment-744369 Share on other sites More sharing options...
lonewolf217 Posted January 23, 2009 Share Posted January 23, 2009 that depends if your sort ASC or DESC Quote Link to comment https://forums.phpfreaks.com/topic/142099-solved-deleting-oldest-entery/#findComment-744373 Share on other sites More sharing options...
mike12255 Posted January 23, 2009 Author Share Posted January 23, 2009 well i've never even heard of DESC soo i guess the other way? Quote Link to comment https://forums.phpfreaks.com/topic/142099-solved-deleting-oldest-entery/#findComment-744381 Share on other sites More sharing options...
revraz Posted January 23, 2009 Share Posted January 23, 2009 Look up the ORDER BY function for MySQL (you haven't stated what DB you are using). Quote Link to comment https://forums.phpfreaks.com/topic/142099-solved-deleting-oldest-entery/#findComment-744383 Share on other sites More sharing options...
mike12255 Posted January 23, 2009 Author Share Posted January 23, 2009 ok thanks, setting this as solved Quote Link to comment https://forums.phpfreaks.com/topic/142099-solved-deleting-oldest-entery/#findComment-744392 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.