[SOLVED] Â Delete records over 24hours old |
1/25/2017 4:42:31 PM |
PHPRunner General questions | |
![]() I am trying to delete records older then 24 hours. I have submit_date field I am going off. I took the post from I started here: http://www.asprunner.com/forums/topic/24424-filter-old-posts/ |
|
![]() |
jadachDevClub member 1/25/2017 |
What you are trying to do requires an action by a user. It is better to delete or archive using a scheduled job in the database. This way each night, your table will remove older records. |
![]() |
Tandy author 1/25/2017 |
What you are trying to do requires an action by a user. It is better to delete or archive using a scheduled job in the database. This way each night, your table will remove older records.
|
![]() |
jadachDevClub member 1/25/2017 |
I do not use MySQL, I use MSSQL Server. There I create a stored procedure to move old records from one table to another based on a datetime field. I then schedule that job to run each night. |
![]() |
HJB 1/26/2017 |
select ... from ... where DateDiff(now(), DateField)<1 |
![]() |
Admin 1/26/2017 |
+1 to what @walk2fly suggests. Deleting records while you only need to hide them is an overkill. Make your query return records for last 24 hours only and if you need physically delete them this is a separate task that cannot be solved with the help of PHPRunner. You will need to write a simple PHP script that deletes data and schedule it using Windows scheduler or a cron job. |
![]() |
HJB 1/27/2017 |
@Tandy Services - https://xlinesoft.com/phprunner/docs/query_designer.htm'>https://xlinesoft.com/phprunner/docs/query_designer.htm |
![]() |
Tandy author 1/28/2017 |
I really do not what to delete the record. I like the hide record as in the other post to replied back to me at. Problem is, If I only hide the post it does not get transferred over to my archive table. I am still trying to figure out how to have the record in the archive table before it is hidden. Was trying to have the record transferred there at the same time the record was made then it can be hidden only like it is now. But the event of transfer before delete is the only one that works for me right now. |
![]() |
lefty 1/28/2017 |
I really do not what to delete the record. I like the hide record as in the other post to replied back to me at. Problem is, If I only hide the post it does not get transferred over to my archive table. I am still trying to figure out how to have the record in the archive table before it is hidden. Was trying to have the record transferred there at the same time the record was made then it can be hidden only like it is now. But the event of transfer before delete is the only one that works for me right now.
|
![]() |
Tandy author 1/28/2017 |
Then do both ; Forget about delete. You can delete the archive at your convenience. After Record Added What you are asking to do is not show the record after you add it but archive to another table , _does not make much sense to me as after you add it , it won't show on your list page_because it is today. It will only get archived and show there. but if that's what you want see below. global $dal; $tbltrucks_archive = $dal->Table("trucks_archive"); $tbltrucks_archive->Value["carrier_id"]=$values["carrier_id"]; $tbltrucks_archive->Value["account_id"]=$values["account_id"]; $tbltrucks_archive->Value["submit_date"]=$values["submit_date"]; $tbltrucks_archive->Value["carrier_name"]=$values["carrier_name"]; $tbltrucks_archive->Value["available_date"]=$values["available_date"]; $tbltrucks_archive->Value["origin_country"]=$values["origin_country"]; $tbltrucks_archive->Value["origin_state"]=$values["origin_state"]; $tbltrucks_archive->Value["origin_city"]=$values["origin_city"]; $tbltrucks_archive->Value["trailer_type"]=$values["trailer_type"]; $tbltrucks_archive->Value["full_partial"]=$values["full_partial"]; $tbltrucks_archive->Value["destination_country"]=$values["destination_country"]; $tbltrucks_archive->Value["destination_state"]=$values["destination_state"]; $tbltrucks_archive->Value["destination_city"]=$values["destination_city"]; $tbltrucks_archive->Add(); Then in Your Main Table Trucks or whatever tablename it is . Go to query and add where clause at end of query Select all your fields like it is listed in query then add after from Trucks. From Trucks WHERE submit_date < DATE_SUB(NOW(),INTERVAL 1 DAY) // mysql This is it . You must have two tables ex... TrucksArchive and Trucks which would be main table that you work with. YOU have to realize that after add it will not show on list page because you have changed your query to 24 hours ago. Don't make much sense._ This will show before the last 24 hours from submit date and your archive table will show all records ever added. You can always query the archive table too. with the same query for submit_date. I would just filter it with past month , day , year etc..... on properties tab for submitdate filter as INTERVAL LIST_ so you can see any dated records.
|
![]() |
lefty 1/28/2017 |
Thanks John, I will give that a shot. But I want it to show in trucks for 24 to 48 hours. Then be hidden off trucks and only show in the truck_archive after that. I am trying to add a button in the truck_archive after that so the poster can re-list the post if need be for another 24 to 48 hours. The only reason I want it to auto hide or delete is that if the load or truck gets moved and the poster does not come back to remove it. Then it does not stay on the list page for more then I am thinking 24 hours but might make it 48 hours, Still in the thinking part of that one. If the truck or load has not moved in that time frame. They can go into the archive and re-list it. If I can get it to post in both spots at the same time. Then I will have to replace the delete button with a hide button that says archive or something along those lines.
|
![]() |
Tandy author 1/29/2017 |
Thank you again John. |