This topic is locked

Building a drivers log

3/9/2009 4:04:21 PM
PHPRunner General questions
W
wonny author

Hi together,
I´m trying to build an drivers log with these five fields

  • date
  • check
  • kmstart
  • destination
  • kmend


and 2 tasks:

  1. Depending on if "check" is checked, it should calculate kmend-kmstart into a new field, which is displayed in list view. If it is not checked, it should calculate the same into another field. ---> I´ve searched the forum and think the solution for this is to do a sql query. Right? But I didn´t found something about my second worry..
  2. On every new Add-page the value oft "kmstart" should be the same as the value of "kmend" from the previous entry - so it is given and you don´t have to enter it. Is this possible to do? And if so, what do I have to do?
    Hope you can help me and forgive my bad English. Stupid german <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=11172&image=1&table=forumtopics' class='bbc_emoticon' alt=':lol:' />

J
Jane 3/11/2009

Hi,
use Before record added/Before record updated events on the Events tab to calculate value and save it in another field.

Here is a sample:

if ($values["check"])

$values["FieldName1"] = $values["kmend"]-$values["kmstart"];

else

$values["FieldName2"] = $values["kmend"]-$values["kmstart"];


To prefill kmstart field use Add page: Before processevent. Select latest kmend value and save it in the $_SESSION variable:

$rs = CustomQuery("select kmend from tablename order by date desc");

$data = db_fetch_array($rs);

$_SESSION["start"] = $data["kmend"];



Then use $_SESSION["start"] as default value on the "Edit as" settings dialog on the Visual Editortab.

W
wonny author 3/12/2009

Oh, great, I´ve just returned from Rome and found your message.
I will rapidly give it a try.
Thank U