Jump to content

Delete MySQL data at a certain time?


verdrm

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/64413-delete-mysql-data-at-a-certain-time/
Share on other sites

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?

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).

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?

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 ;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.