This topic is locked
[SOLVED]

 Help on Custom code - Please

9/3/2012 5:25:46 AM
PHPRunner General questions
D
drk2009 author

Hello,

I need some help on completing my custom come, I have gone blank and nothing is fixing it.
I have the folling which works great calculating a date based on working days:



global $conn;

$str = "SELECT * FROM `holiday` order by `H_Date` desc";

$rs = db_query($str,$conn);

$holidayList = db_fetch_array($rs);
$j = $i = 0; //changed this to 0 or you were always starting one day ahead

$given_date = $data["F_Day"];

$tmp1 = strtotime($given_date); //worked out a timstamp to start with

while($i < 10)

{

$tmp2 = strtotime("+$j day", $tmp1);

$day = strftime("%A",$tmp2);

//echo strftime("%d-%m-%Y",$tmp2);
$tmp = strftime("%d-%m-%Y",$tmp2);

if(($day != "Sunday") && ($day != "Saturday" )&&(!in_array($tmp, $holidayList)))

{

$i = $i + 1;

$j = $j + 1;



}

else

{

$j = $j + 1;



}

}

$j = $j -1;

$newdate = strtotime("+$j day",$tmp1);

$working_days = strftime("%A, %d-%m-%Y",$newdate);

$value = $working_days;


I need to change the code so it give me diferent dates based on what data is contain in

other fields, but no matter what I do it is not working, can someone please help me fix it, it

driving me bananas. My IF and ELSE IF do not seem to be doing anything.

Here it is!!



global $conn;

$str = "SELECT * FROM `holiday` order by `H_Date` desc";

$rs = db_query($str,$conn);

$holidayList = db_fetch_array($rs);
$j = $i = 0; //changed this to 0 or you were always starting one day ahead

$given_date = $data["F_Day"];

$tmp1 = strtotime($given_date); //worked out a timstamp to start with
if (($value = $data["P_SentTo"] == "Trainer")){

($i < 7) ;}
elseif (($value = $data["P_SentTo"] == "Venue")){

($i < 5) ;}
elseif (($value=$data["Course_Type"] = "FF")&&($value = $data["P_SentTo"] == "Venue")){

($i < 15) ;}
{

$tmp2 = strtotime("+$j day", $tmp1);

$day = strftime("%A",$tmp2);

//echo strftime("%d-%m-%Y",$tmp2);
$tmp = strftime("%d-%m-%Y",$tmp2);

if(($day != "Sunday") && ($day != "Saturday" )&&(!in_array($tmp, $holidayList)))

{

$i = $i + 1;

$j = $j + 1;



}

else

{

$j = $j + 1;



}

}

$j = $j -1;

$newdate = strtotime("+$j day",$tmp1);

$working_days = strftime("%A, %d-%m-%Y",$newdate);

$value = $working_days


Anyone willing?

Thank you.

D
drk2009 author 9/5/2012

For anyone interested, here is the code that worked for me.

I had to create a table with the values under $data on the "if section", before I had

them as a list of values on the lookup wizard, in addition to fixing the

code a bit.
This code is to find 6, 7 and 16 working days in the past from a date.



global $conn;

$str = "SELECT * FROM `holiday` order by `H_Date` desc";

$rs = db_query($str,$conn);

$holidayList = db_fetch_array($rs);

//--Replace $values with $data and Be careful with your case, These values are Case Sensitive---
$j = $i = 0; //changed this to 0 or you were always starting one day ahead

$given_date = $data["F_Day"];

$tmp1 = strtotime($given_date); //worked out a timstamp to start with

while($i < 7)

{

$tmp2 = strtotime("-$j day", $tmp1);

$day = strftime("%A",$tmp2);
$tmp = strftime("%d-%m-%Y",$tmp2);

if(($day != "Sunday") && ($day != "Saturday" )&&(!in_array($tmp, $holidayList)))

{

$i = $i + 1;

$j = $j + 1;



}

else

{

$j = $j + 1;



}

}

$j = $j -1;

$newdate = strtotime("-$j day",$tmp1);

$working_days = strftime("%A, %d-%m-%Y",$newdate);

//-------------------------------------

$j1 = $i1 = 0; //changed this to 0 or you were always starting one day ahead

$given_date1 = $data["F_Day"];

$tmp3 = strtotime($given_date1); //worked out a timstamp to start with

while($i1 < 6)

{

$tmp4 = strtotime("-$j1 day", $tmp3);

$day1 = strftime("%A",$tmp4);
$tmpp = strftime("%d-%m-%Y",$tmp4);

if(($day1 != "Sunday") && ($day1 != "Saturday" )&&(!in_array($tmpp, $holidayList)))

{

$i1 = $i1 + 1;

$j1 = $j1 + 1;



}

else

{

$j1 = $j1 + 1;



}

}

$j1 = $j1 -1;

$newdate1 = strtotime("-$j1 day",$tmp3);

$working_days1 = strftime("%A, %d-%m-%Y",$newdate1);

//-------------------------------------------------

$j2 = $i2 = 0; //changed this to 0 or you were always starting one day ahead

$given_date2 = $data["F_Day"];

$tmp5 = strtotime($given_date2); //worked out a timstamp to start with

while($i2 < 16)

{

$tmp6 = strtotime("-$j2 day", $tmp5);

$day2 = strftime("%A",$tmp6);
$tmpa = strftime("%d-%m-%Y",$tmp6);

if(($day2 != "Sunday") && ($day2 != "Saturday" )&&(!in_array($tmpa, $holidayList)))

{

$i2 = $i2 + 1;

$j2 = $j2 + 1;



}

else

{

$j2 = $j2 + 1;



}

}

$j2 = $j2 -1;

$newdate2 = strtotime("-$j2 day",$tmp5);

$working_days2 = strftime("%A, %d-%m-%Y",$newdate2);

//-------------------------------------------------

if (($value=$data["P_Sent_To"]=="Trainer")){

$value=$working_days;}

elseIf (($value=$data["P_Sent_To"]=="Venue")){

$value=$working_days1;}

elseIf (($value=$data["P_Sent_To"]=="RLSSA")){

$value=$working_days2;}