Adding a number of days

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
marisoft
User
Posts: 209

Adding a number of days

Post by marisoft »

Hi,

When inserting a record I retrieve a record in a related table.
From that record a column contains a number of dates that is to be added to a column in the new record before saving.

Below code from inserting event fails at line marked ***THIS FAILS
What could be wrong here.

TIA
/Poul

function Row_Inserting($rsold, &$rsnew) {
// Enter your code here
// To cancel, set return value to FALSE

 $rs =& $rsnew;
 $bevis_ubegraenset=0;
 $bevis_dageloebetid=0;
 $bevis_dato=0;
 
 global $conn;          
 $sSqlWrk = "SELECT ubegraenset, dageloebetid FROM sr_bevistyper WHERE bevistype ='". $rs["type"] . "'"  ;      
 $rswrk = $conn->Execute($sSqlWrk);

 if ($rswrk)                                     
 {
   $bevis_ubegraenset=$rswrk->fields[0];
   $bevis_dageloebetid=$rswrk->fields[1];  
  
   $bevis_dato = strtotime($rs["dato"]);

*** THIS FAILS: $rs["datoudloeb"] = date('m-d-Y', strtotime( ‘+’ . $bevis_dageloebetid .’ day’ , strtotime ( $bevis_dato ) ) );

 } 

return TRUE;

}


scs
User
Posts: 694

Post by scs »

1) $rs =& $rsnew; <=== not needed.

just use the $rsnew

2) below 3 lines not necessary.
global $conn;
$sSqlWrk = "SELECT ubegraenset, dageloebetid FROM sr_bevistyper WHERE bevistype ='". $rs["type"] . "'" ;
$rswrk = $conn->Execute($sSqlWrk);

but replace with
$rswrk = ew_Execute(SELECT ubegraenset, dageloebetid FROM sr_bevistyper WHERE bevistype ='". $rsnew["type"] . "'")

3) $bevis_dato = strtotime($rs["dato"]);
*** THIS FAILS: $rs["datoudloeb"] = date('m-d-Y', strtotime( ‘+’ . $bevis_dageloebetid .’ day’ , strtotime ( $bevis_dato ) ) );
$bevis_dato already strtotime. Why fail line still strtotime again?

Correct way should be (2 line become 1 line)
$rsnew["datoudloeb"] = date('m-d-Y', strtotime( ‘+’ . $bevis_dageloebetid .’ day’ , strtotime ( $rsnew["dato"] ) ) );

Please adjust to your needs.

Hope this help.


marisoft
User
Posts: 209

Post by marisoft »

Thanks scc

Just what I needed to get going.

/Poul


Post Reply