verdrm Posted August 11, 2007 Share Posted August 11, 2007 I am building a lunch ordering system for a company. The employees can login, order lunch, and the administrator can see what everyone ordered for lunch in the admin panel. The problem is that when the employees enter data, it stays in the database until they update it. If an employee is sick, their lunch order from the previous day is still in the database. Is there a way to clear those values they enter at a certain time in MySQL or does anyone have a suggestion as to how to clear the data after the lunch hour each day? Quote Link to comment https://forums.phpfreaks.com/topic/64413-delete-mysql-data-at-a-certain-time/ Share on other sites More sharing options...
hitman6003 Posted August 11, 2007 Share Posted August 11, 2007 Just issue a query to the db... DELETE FROM lunch_orders WHERE order_time < DATE_SUB(NOW(), INTERVAL 2 HOUR) ...would delete orders more than two hours old. Quote Link to comment https://forums.phpfreaks.com/topic/64413-delete-mysql-data-at-a-certain-time/#findComment-321129 Share on other sites More sharing options...
lightningstrike Posted August 11, 2007 Share Posted August 11, 2007 Read about cron jobs on UNIX/Linux or Scheduled Tasks on a Windows server. And issue a query similar to the one above. Quote Link to comment https://forums.phpfreaks.com/topic/64413-delete-mysql-data-at-a-certain-time/#findComment-321130 Share on other sites More sharing options...
verdrm Posted August 11, 2007 Author Share Posted August 11, 2007 I had thought about Scheduled Tasks already, but it isn't running on my own servers, it is a "portable" script. I assume I would just add the DELETE FROM code onto the main page, that way when a user logs in it would delete their old order and they can repost a new order? Is my thinking correct? Quote Link to comment https://forums.phpfreaks.com/topic/64413-delete-mysql-data-at-a-certain-time/#findComment-321148 Share on other sites More sharing options...
ILYAS415 Posted August 11, 2007 Share Posted August 11, 2007 Yh u can do that but then itll delete lunch theyve ordered a minute ago (maybe). There is something you can do tho. If your using cpanel then their should already be a cron thing in the cpanel. Tell the cron to run a script every 24 hours (or every day). Quote Link to comment https://forums.phpfreaks.com/topic/64413-delete-mysql-data-at-a-certain-time/#findComment-321230 Share on other sites More sharing options...
calabiyau Posted August 11, 2007 Share Posted August 11, 2007 If you can still make these changes to ytour database, you could add a datetime field or a timestamp when the order was placed and then when you are selecting your orders for the day, couldn't you just select orders that were placed within a certain range of time? Quote Link to comment https://forums.phpfreaks.com/topic/64413-delete-mysql-data-at-a-certain-time/#findComment-321239 Share on other sites More sharing options...
AndyB Posted August 11, 2007 Share Posted August 11, 2007 ... but then itll delete lunch theyve ordered a minute ago (maybe). DELETE FROM lunch_orders WHERE order_time < DATE_SUB(NOW(), INTERVAL 2 HOUR) ...would delete orders more than two hours old. Quote Link to comment https://forums.phpfreaks.com/topic/64413-delete-mysql-data-at-a-certain-time/#findComment-321253 Share on other sites More sharing options...
Gamic Posted August 11, 2007 Share Posted August 11, 2007 You could be looking at the problem the wrong way. You don't need to delete anything, you just need to show orders from today. select * from lunch_order where lunch_order.ordertime>[begining of today] and lunch_order.ordertime<[now()/end of today] This would then allow you to keep employees orders and find out over information from the data at a later date (like, how much your spending to feed each employee Quote Link to comment https://forums.phpfreaks.com/topic/64413-delete-mysql-data-at-a-certain-time/#findComment-321275 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.