Dear Appgini forum,
does anyone an idea for solving the following problem:
- I'm using Appgini 5.75
- Within my Appgini application I have a table, let's call it products.
- This table has the fields: ID, CREATEDDATE, VALID_TO, STATUS,...
- ID: primary key, CREATEDDATE: date, VALID_TO: date, STATUS: varchar (10)
- I would like to update the STATUS field every time when a user calls the Table views from "products" as follows:
>> If ((the date from today) - (VALID_TO)) < 0 then STATUS = "OK"
>> If ((the date from today) - (VALID_TO)) => 0 then STATUS = "NOT OK"
- I tried to implement the condition above in the tablename_init hook, so when the Tableview from the table "products" is called the STATUS fields are showing the updated values (OK, NOT OK etc.)
- But however I could not find a way how to retrieve each data from the table "products" within the foreach loop to implement the conditions above and update the STATUS field!
Anyone a hint for me?
PS:
1. The tutorial under https://bigprof.com/appgini/tips-and-tu ... eview-data was unfortunately not a help for me ;-(
2. I did not understand how to use the DataList-object under https://bigprof.com/appgini/help/advanc ... ist-object
Thx a lot
Yilmaz
Init hook question
Re: Init hook question
Hi Yilmaz,
I would think that it depends on how you want to accomplish your task, if this hook is the correct one.
Using this hook: Why not check recalculate all fields (maybe limit to once a day with an extra field in some table of yours) using php?
I suggest something like this (not tested code, just written down here):
Olaf
I would think that it depends on how you want to accomplish your task, if this hook is the correct one.
Using this hook: Why not check recalculate all fields (maybe limit to once a day with an extra field in some table of yours) using php?
I suggest something like this (not tested code, just written down here):
Code: Select all
$res = sql("Select * from products", $eo);
while($row = db_fetch_assoc($res)){
If (date("Ymd")) - (date($format, $row['VALID_TO']))) < 0 {
$STATUS = "OK";
}
else
{
$STATUS = "NOT OK";
}
$res_up1 = sql("UPDATE products SET STATUS= '" . $STATUS, $eo);
}
Some postings I was involved, you might find useful:
SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button; Place a search on details view
SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button; Place a search on details view
SOLVED: Re: Init hook question
Thx a lot for your hint Olaf! Great idea!
I've done it using php and (like your suggestion) per cronjob executing the php file once a day:
Kind regards,
Yilmaz
I've done it using php and (like your suggestion) per cronjob executing the php file once a day:
Code: Select all
$select_abfrage = "SELECT * FROM loans";
$select_ergebnis = mysqli_query($connect, $select_abfrage);
while($dsatz = mysqli_fetch_assoc($select_ergebnis)){
$differenz = strtotime($dsatz['loandate_till']) - strtotime(date("m/d/Y"));
$resttage = $differenz/86400;
If ($resttage >= 5){
$statusquo = "green";
}elseif (($resttage > 0) && ($resttage < 5)) {
$statusquo = "orange";
} else{
$statusquo = "red";
}
$id = $dsatz["id"];
$update_abfrage = "UPDATE loans SET status = '$statusquo' WHERE id = '$id'";
mysqli_query($connect, $update_abfrage);
}
Yilmaz
Re: Init hook question
Hi Yilmaz,
great to hear this worked.
Btw. do you know that, since you use color coding now, you might add this to your table view in color?
Looks like this: It's very simple to accomplish and described here: viewtopic.php?f=4&t=2876#p9287
Olaf
great to hear this worked.
Btw. do you know that, since you use color coding now, you might add this to your table view in color?
Looks like this: It's very simple to accomplish and described here: viewtopic.php?f=4&t=2876#p9287
Olaf
Some postings I was involved, you might find useful:
SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button; Place a search on details view
SingleEdit - Prevent concurrent edits on records; Field Permissions; Column-Value-Based-Permissions; Custom (error) message; Audit Log; Backup your database; Two Factor Authentication; Block brute force (failed) logins; Add 2nd SAVE CHANGES button; Place a search on details view