Page 1 of 1
Auto delete
Posted: 2015-12-08 00:33
by TandyServices
Hello all,
Hope someone can help me out here. I am new to AppGini as well as database.
I am building a Load Board for trucking.
I have 4 different tables that all have date fields in them. What I need to figure out is after that date(say midnight) to have those records auto delete. But I would like to have a log of all that was in those tables.
The reason I need this is because old records will not help. If a truck gets loaded that day. And the owner of that record does not come back in to delete it. and say I have thousands of members putting there records in every day. That page will never end so I need the whole line to be deleted off the page.
But in the same time I might need to go back and find an old record. So if I can save it all to a log file on the server, I can still go back and see what went on for lets say ID key 100 or 125..
Any help would be great if this can even be done with AppGini
Thank You
James
Re: Auto delete
Posted: 2015-12-08 19:41
by a.gneady
Hmm ... instead of deleting old records and keeping a copy of them in a log, how about applying a default filter to the table to display only today's records? And if you want to view older records, you can clear the filter. Here is
how you can apply a default filter to a table.
Re: Auto delete
Posted: 2015-12-08 20:35
by TandyServices
Ok. Then how would I write that out? Plus that would still over crowd the database if there are thousands of records. I would still need to add them to a file for later use, then prune them off the database so the database does not get slow..
Re: Auto delete
Posted: 2015-12-09 20:19
by a.gneady
Assuming the date field in your records is the third field in the table for example, the command to add to the hook (as explained in the above link) would look like this:
Code: Select all
addFilter(1, 'and', 3, 'equal-to', date('m/d/Y'));
This assumes your date format is month/day/year ... If you use another format, for example day.month.year, the command would look like:
Code: Select all
addFilter(1, 'and', 3, 'equal-to', date('d.m.Y'));
Plus that would still over crowd the database if there are thousands of records
MySQL is designed to handle millions of records efficiently. Moreover, you can add an index on the date field and this would make it very fast to display results when using the above filter. I see no reason to be worried about this unless you have very limited space on your server, which would make it unpractical to consider a log file as well.
Re: Auto delete
Posted: 2015-12-09 21:38
by TandyServices
It does not work for me.. My field is the second one. The first one is the ID then pickup date. Here is my first few line to make sure it is right and it is in my hooks folder and file is loads.php
<?php
// For help on using hooks, please refer to
http://bigprof.com/appgini/help/working ... tion/hooks
function loads_init(&$options, $memberInfo, &$args){
if(!$_POST['FilterField'][1] && !$_GET['FilterField'][1]){
addFilter(1, 'and', 2, 'less-than-or-equal-to', date('m/d/Y'));
}
return TRUE;
}
function loads_header($contentType, $memberInfo, &$args){
$header='';
switch($contentType){
case 'tableview':
$header='';
break;
case 'detailview':
$header='';
break;
Re: Auto delete
Posted: 2015-12-10 21:31
by a.gneady
What happens when you use this code?
Since you are using 'less-than-or-equal-to', the filter you defined would display records of today and all older ones. Is that what you need?
Re: Auto delete
Posted: 2015-12-10 21:34
by TandyServices
No.. I had your way as well.. I just changed it to see if anything happens.. nothing happens at all, in any way. That is why I think I did not put the code in the right spot..
Re: Auto delete
Posted: 2015-12-14 04:25
by a.gneady
By "nothing happens at all" do you mean all data is displayed without any filtering, or nothing is displayed? If it is the former (that is, all data is displayed), try clicking the 'Filter' button to open the filters page, and see if any filters are defined.
Re: Auto delete
Posted: 2015-12-14 04:50
by TandyServices
The page turn blank(white screen).. I took that code out and then I went into the filters on the page and added
PickUp Date then Equal to then date('m/d/Y')
That worked. But I can't not get the code in the hooks to work..
Here is what I have in there:
function loads_init(&$options, $memberInfo, &$args){
if(!$_POST['FilterField'][1] && !$_GET['FilterField'][2]){
addFilter(1, 'and', 3, 'equal-to', date('m/d/Y'));
return TRUE;
Re: Auto delete
Posted: 2015-12-15 10:23
by a.gneady
This seems to be due to a missing closing } -- line 4 below:
Code: Select all
function loads_init(&$options, $memberInfo, &$args){
if(!$_POST['FilterField'][1] && !$_GET['FilterField'][2]){
addFilter(1, 'and', 3, 'equal-to', date('m/d/Y'));
}
return TRUE;
}
Re: Auto delete
Posted: 2015-12-16 10:49
by TandyServices
Ok that work but here is the way it works that I needed it.. Only today and days to come show.. yesterday and everything else does not show:
function loads_init(&$options, $memberInfo, &$args){
if(!$_POST['FilterField'][1] && !$_GET['FilterField'][1]){
addFilter(1, 'and', 3, 'greater-than-or-equal-to', date('m/d/Y'));
}
return TRUE;
}