Generating Future dates based on condition

I am working on a project management system and I am trying to get an estimated start date based on the previous projects length and duration.  I am putting a "dummy" project in the system with a completion day to help base the future dates off of.

I want each project to look at the previous projects completion date.  If that is not set, then it should look at the dates table and see if there are any dates that have been added and add the task length's accordingly.

The dates that are held in the dates table are the start date (which is set by the programmer who will press a start button to begin a project), a pause date (which can be set by the programmer if the project is going on a temporary hold), a resume date, (which will be again set by the programmer when the paused project will be resumed).

The code below is basing all projects based off of the completion date, and is not looking at the previous project to calculate dates.  
 
foreach($programmers AS $programmer)
	{
	//Set End Date for last completed project!	
	$lastCompletedProject = lastCompletedProject($programmer);
	
	echo 'Last Completed Project: ' . $lastCompletedProject . '<br />';
	
	//Get Projects
	$getProjects = mysql_query("SELECT helpDesk_projectList.id, createdFor, projectName, projectPriority, projectStatus, programmerAssigned
													FROM helpDesk_projectList
													LEFT JOIN helpDesk_projectAssignments ON helpDesk_projectList.id = helpDesk_projectAssignments.projectId
													WHERE (projectStatus = '1' OR projectStatus = '2' OR projectStatus = '3') and programmerAssigned = '".$programmer."'") or die("Cannot get current projects: " . mysql_error());
						
	if(mysql_num_rows($getProjects) > 0)
		{
		$i = 0;
		$prevRow = 0;
		
		while($pData = mysql_fetch_assoc($getProjects))
			{
			//Sum Days of Tasks for each project
			$getTasks = mysql_query("SELECT SUM(taskLength) as taskLength FROM helpDesk_projectTasks WHERE projectId = '".$pData['id']."'") or die("Cannot get Tasks: " . mysql_error());

			if(mysql_num_rows($getTasks) > 0)
				{
				while($taskData = mysql_fetch_assoc($getTasks))
					{
					$taskLength = $taskData['taskLength'];
					}
				}
				
			//Temp BS
			$deadlineDate = date("Y-m-d", strtotime($projectLengthMinusOne . ' weekdays', strtotime($startDate)));
				
			//Check for any other projects that may have dates associated with them.
			$checkProjects = mysql_query("SELECT actionDate, actionType FROM helpDesk_projectDates WHERE projectId = '".$pData['id']."' AND actionType <> '1'") or die("Cannot check projects: " . mysql_error());
			
			if(mysql_num_rows($checkProjects) > 0)
				{
				while($cpData = mysql_fetch_assoc($checkProjects))
					{
					//add dates to the last action date.
					$lastActionDate = $cpData['actionDate'];
					$nextStart = 'duh' . date("Y-m-d", strtotime($taskLength . ' weekdays', strtotime($lastActionDate)));
					}
				}
				
			else
				{
				if($prevRow == $currentRow)
					{
					//Last completed + 1
					$nextDay =  date("Y-m-d", strtotime('+1 weekday', strtotime($lastCompletedProject)));
					}
					
				else
					{
					$nextDay = 'Not sure??';
					}
					
				//Add dates to last completed date.
				$endDate = 'lol ' . date("Y-m-d", strtotime($taskLength . ' weekdays', strtotime($nextDay)));
				}
					
		
		//Add Task Length to prevoius project Completion Date
			
		echo '<tr>
					<td ' . $row_color . '>'.$pData['id'] . '</td>
					<td ' . $row_color . '>'.$pData['projectName'] . '</td>
					<td ' . $row_color . '>'.getCkname($pData['programmerAssigned']) . '</td>
					<td ' . $row_color . '>'.$pData['projectPriority'] . '</td>
					<td ' . $row_color . '>'.$estimatedStart . '</td>
					<td ' . $row_color . '>'.$estimatedEnd . '</td>
					<td ' . $row_color . '>'.$taskLength .  '</td>
					<td ' . $row_color . '>'.$nextDay . '</td>
					<td ' . $row_color . '>'.$endDate . '</td>
					<td ' . $row_color . '><span class="boldblacklinks"><a href="editProject.php?projectId='.$projectId.'" class="iframetall">Edit</a></span></td>
				</tr>';
			
			$prevRow = $currentRow;
			}
		}
	}

Open in new window

Screenshot.png
helpDesk-projectAssignments.sql
helpDesk-projectDates.sql
helpDesk-projectList.sql
LVL 1
t3chguyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
What is the question?  Do you want to know how to do date arithmetic?  The DateTime extension is helpful.  This article may get you started.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html
0
t3chguyAuthor Commented:
Not so much date arithmetic, but how can I use the last date generated to calculate future dates?

For example, in my screenshot, The Dashboard Updates project starts on 10-15 and has a duration of two days.  That would mean that project Test 2 should start on 10-18 and last for three days for an end date of 10-21.  Right now, its basing all start and end dates based off of the same date which is 10-14.

The question is about iterating dates based on the previous row's values.
0
Ray PaseurCommented:
That sounds like date arithmetic to me.  I'll see if I can give you an example.  It won't use a data base, but the step from rows in a query results set to the code I show will not be very big at all.
0
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Ray PaseurCommented:
Please see: http://www.laprbass.com/RAY_temp_t3chguy.php

<?php // RAY_temp_t3chguy.php 2013-10-16
error_reporting(E_ALL);
echo '<pre>';

// SCHEDULE BASED ON CONSECUTIVE TASKS
// http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28268506.html#a39576941

// USE THIS TO SIMULATE A SET OF TASK DURATIONS
$tasks = array
( 'one' => 2
, 'two' => 3
, 'tre' => 4
, 'for' => 1
, 'fiv' => 2
)
;

// WE WILL CAPTURE THE TASK START AND END DAYS HERE
$out = array();

// OUR STARTING DAY WILL BE TOMORROW
$alpha = date('Y-m-d', strtotime('Tomorrow'));

// ADD IN THE TASKS
foreach ($tasks as $item => $num)
{
    // THE NUMBER OF WHOLE DAYS
    $omega = date('Y-m-d', strtotime($alpha . " + $num DAYS - 1 SECOND"));

    // SAVE THE RESULTS
    $ndx = $item . "($num days)";
    $out[$ndx] = array("Start" => $alpha, "Ended" => $omega);

    // START THE NEXT TASK ON THE DAY FOLLOWING THE PRIOR COMPLETION
    $alpha = date('Y-m-d', strtotime($omega . " + 1 DAY"));
}

print_r($out);

Open in new window

At some point you may also want to consider weekends and holidays as gaps in the schedule.  See practical application #9 in this article.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_201-Handling-date-and-time-in-PHP-and-MySQL.html
0
t3chguyAuthor Commented:
That part I understand, but do not understand how to apply that to a while loop for my specific use.
0
Ray PaseurCommented:
Are you wanting to update the data base table with start / end dates?  Or are you looking to insert new rows?
0
t3chguyAuthor Commented:
Neither, hoping just to do this dynamically in the code.
0
Ray PaseurCommented:
Looking at this...

$nextStart = 'duh' . date("Y-m-d", strtotime($taskLength . ' weekdays', strtotime($lastActionDate)));

Open in new window

Not sure what effect the 'duh' is having on the process, but if it's getting carried forward into a future computation, it won't be helpful.

Any chance you want something like this?

// MAKE ISO-8601 OF THE LAST DATE + 1 
$lastActionDate = date('Y-m-d', strtotime($lastActionDate));

// ADD WEEK DAYS
$nextStart      = date('Y-m-d', strtotime($lastActionDate . " + $taskLength WEEKDAYS"));

Open in new window

If that's not it, please show me an isolated example of the while() loop with a small test set in an array.
0
t3chguyAuthor Commented:
Programmer 1 had a last completion date of 2013-10-14

Project ID 3 should start on 10-15 and have a duration of 2 days ending on 10/16.
Project ID 5 should start on 10-17 and have a duration of 3 days ending on 10/20.


	$getProjects = mysql_query("SELECT helpDesk_projectList.id, createdFor, projectName, projectPriority, projectStatus, programmerAssigned
													FROM helpDesk_projectList
													LEFT JOIN helpDesk_projectAssignments ON helpDesk_projectList.id = helpDesk_projectAssignments.projectId
													WHERE (projectStatus = '1' OR projectStatus = '2' OR projectStatus = '3') and programmerAssigned = '".$programmer."'") or die("Cannot get current projects: " . mysql_error());
	
	if(mysql_num_rows($getProjects) > 0)
		{
		$i = 0;
		$prevRow = 0;
		
		while($pData = mysql_fetch_assoc($getProjects))
			{
			//Sum Days of Tasks for each project
			$getTasks = mysql_query("SELECT SUM(taskLength) as taskLength FROM helpDesk_projectTasks WHERE projectId = '".$pData['id']."'") or die("Cannot get Tasks: " . mysql_error());

			if(mysql_num_rows($getTasks) > 0)
				{
				while($taskData = mysql_fetch_assoc($getTasks))
					{
					$taskLength = $taskData['taskLength'];
					}
				}
						
			//Check for any other projects that may have dates associated with them.
			$checkProjects = mysql_query("SELECT actionDate, actionType FROM helpDesk_projectDates WHERE projectId = '".$pData['id']."' AND actionType <> '1'") or die("Cannot check projects: " . mysql_error());
			
			if(mysql_num_rows($checkProjects) > 0)
				{
				while($cpData = mysql_fetch_assoc($checkProjects))
					{
					//add dates to the last action date.
					$lastActionDate = $cpData['actionDate'];
					$nextStart = date("Y-m-d", strtotime($taskLength . ' weekdays', strtotime($lastActionDate)));
					}
				}
				
			else
				{
				//Last completed + 1
				$nextDay =  date("Y-m-d", strtotime('+1 weekday', strtotime($lastCompletedProject)));
				}
			
				//Add dates to last completed date.
				$endDate = date('Y-m-d', strtotime($alpha . " + $taskLength DAYS - 1 SECOND"));
				
					
				// MAKE ISO-8601 OF THE LAST DATE + 1 
				$lastActionDate = date('Y-m-d', strtotime($nextDay));

				// ADD WEEK DAYS
				$nextEnd      = date('Y-m-d', strtotime($lastActionDate . " + $taskLength WEEKDAYS"));

				//Add Task Length to prevoius project Completion Date
			
				echo '<tr>
							<td ' . $row_color . '>'.$pData['id'] . '</td>
							<td ' . $row_color . '>'.$pData['projectName'] . '</td>
							<td ' . $row_color . '>'.getCkname($pData['programmerAssigned']) . '</td>
							<td ' . $row_color . '>'.$lastActionDate . '</td>
							<td ' . $row_color . '>'.$nextEnd . '</td>
							<td ' . $row_color . '><span class="boldblacklinks"><a href="editProject.php?projectId='.$projectId.'" class="iframetall">Edit</a></span></td>
						</tr>';
			
			$prevRow = $currentRow;
			}
		}
	}

Open in new window

0
Ray PaseurCommented:
Please add error_reporting(-1) to the top of this script so we can be sure that it's not relying on any undefined variables.

This is line 34:

$nextStart = date("Y-m-d", strtotime($taskLength . ' weekdays', strtotime($lastActionDate)));

Open in new window

What is the value that the script creates in $nextStart?  Please print it out with var_dump() so we can see what is begin created there.
0
t3chguyAuthor Commented:
$nextStart returns

NULL

NULL

NULL 

Open in new window

0
Ray PaseurCommented:
That's kind of what I expected.  It looks like the intent of that line of code is to add some number of weekdays (identified in the variable $taskLength) to a date identified in the variable $lastActionDate.  If that's a fair explanation, please try that line like this and let's see what var_dump() can tell us after the code change.

$nextStart = date("Y-m-d", strtotime($lastActionDate . " + $taskLength weekdays"));

Open in new window

Please correct any typos - I cannot test any of this, so I'm coding without a net.
0
t3chguyAuthor Commented:
It still returns NULL.  Even though the code above it, ($lastActionDate) is not empty.
0
Ray PaseurCommented:
There is something else going wrong here.  Neither of the methods of computing the future date return NULL.

<?php // RAY_temp_t3chguy_1.php 2013-10-16
error_reporting(E_ALL);
echo '<pre>';

// SCHEDULE BASED ON CONSECUTIVE TASKS
// http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28268506.html#a39576941

$taskLength = 4;
$lastActionDate = '2013-10-16';
$nextStart = date("Y-m-d", strtotime($taskLength . ' weekdays', strtotime($lastActionDate)));
var_dump($nextStart);

$nextStart = date("Y-m-d", strtotime($lastActionDate . " + $taskLength weekdays"));
var_dump($nextStart);

Open in new window

I'm beginning to think there is a program logic error that is skipping some or all of the code.  It may need to be rewritten to find the error.  Here's an example of the sort of code that should be refactored, and an example of how to run queries and show the errors, if any.

<?php // RAY_temp_t3chguy_3.php 2013-10-16
error_reporting(E_ALL);
echo '<pre>';

// SCHEDULE BASED ON CONSECUTIVE TASKS
// http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28268506.html#a39576941


// WHAT WE HAVE
$getTasks = mysql_query("SELECT SUM(taskLength) as taskLength FROM helpDesk_projectTasks WHERE projectId = '".$pData['id']."'") or die("Cannot get Tasks: " . mysql_error());
if(mysql_num_rows($getTasks) > 0)


// THIS IS MORE LIKE WHAT WE NEED
$getTasksQry = "SELECT SUM(taskLength) as taskLength FROM helpDesk_projectTasks WHERE projectId = '{$pData["id"]}' ";
$getTasks    = mysql_query($getTasksQry);
if (!$getTasks)
{
    $err = "<br>FAIL: $getTasksQry";
    $err .= "<br>ERRNO: " . mysql_errno();
    $err .= "<br>ERROR: " . mysql_error();
    trigger_error($err, E_USER_ERROR);
}
$numTasks = mysql_num_rows($getTasks);
if ($numTasks)
{
    echo "<br>getTasksQry FOUND $numTasks ROWS";
}
else
{
    echo "<br>getTasksQry FOUND NO ROWS";
}

Open in new window

This article shows how to use PHP and MySQL together.  You're going to have to convert all of the procedural MySQL to MySQLi or PDO anyway, might as well start with good examples of how to do it.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html
0
t3chguyAuthor Commented:
Ok, I moved your code into my pre-existing block.

There are three projects in the system.

Running your code returned the following:

getTasksQry FOUND 1 ROWS
getTasksQry FOUND 1 ROWS
getTasksQry FOUND 1 ROWS
0
Ray PaseurCommented:
Great - we're moving in the right direction.

Do you expect the query to find 1 row every time?  If so, you might want to add LIMIT 1 to the query so the SQL engine doesn't do a table scan every time (see AntiPHPractice #26).

Next, please use print_r() to print out the rows that were found so we can see what data is in there.
0
t3chguyAuthor Commented:
Yes, it should typically always always return one row.  I will add that limit to the query.

getTasksQry FOUND 1 ROWSArray
(
    [taskLength] => 2
)

getTasksQry FOUND 1 ROWSArray
(
    [taskLength] => 3
)



getTasksQry FOUND 1 ROWSArray
(
    [taskLength] => 63
)

Open in new window

0
Ray PaseurCommented:
Good.   We know that taskLength makes sense.  Next step is to repeat this pattern of data discovery on the other data elements.  Run the queries, print them out and make sure every one of them is showing what you expect.
0
t3chguyAuthor Commented:
getTasksQry FOUND 1 ROWS Last Completed Project: 2013-10-14
Project Id: 3 -  2 days - 2013-10-15 - 2013-10-17

getTasksQry FOUND 1 ROWS Last Completed Project: 2013-10-14
Project Id: 5 -  3 days - 2013-10-15 - 2013-10-18

Open in new window


Everything is looking good.  Here is the part that needs to be changed somehow.

Project ID 3 is displaying exactly how it should.

HOWEVER, Project ID # 5 is to be completed AFTER project Id #3, but there is no logic in the code stating that these projects do not run at the same time, but instead, one after another.  

The logic to make that happen is what I'm unsure of.
0
Ray PaseurCommented:
Yes, I'm unsure of it, too.  Can you please post the script as it is now?  I'll try to follow the variables.  In a semi-related matter, you might want to get the assistance of a data base administrator.  It might be worth rethinking the tables structure.
0
t3chguyAuthor Commented:
foreach($programmers AS $programmer)
	{
	echo '<strong>' . getCkname($programmer) . ' Projects</strong><br /><br />';
	
	//Get Projects
	$getProjects = mysql_query("SELECT helpDesk_projectList.id, createdFor, projectName, projectPriority, projectStatus, programmerAssigned
													FROM helpDesk_projectList
													LEFT JOIN helpDesk_projectAssignments ON helpDesk_projectList.id = helpDesk_projectAssignments.projectId
													WHERE (projectStatus = '1' OR projectStatus = '2' OR projectStatus = '3') and programmerAssigned = '".$programmer."'") or die("Cannot get current projects: " . mysql_error());
	
	if(mysql_num_rows($getProjects) > 0)
		{
		$z = 1;
		
		while($pData = mysql_fetch_assoc($getProjects))
			{
			$getTasksQry = "SELECT SUM(taskLength) as taskLength FROM helpDesk_projectTasks WHERE projectId = '{$pData["id"]}' LIMIT 1";
			$getTasks    = mysql_query($getTasksQry);
			if (!$getTasks)
				{
				$err = "<br>FAIL: $getTasksQry";
				$err .= "<br>ERRNO: " . mysql_errno();
				$err .= "<br>ERROR: " . mysql_error();
				trigger_error($err, E_USER_ERROR);
				}

			$numTasks = mysql_num_rows($getTasks);

			while($tData = mysql_fetch_assoc($getTasks))
				{
				$taskLength = $tData['taskLength'];
				}
				
			$currentProject = $pData['id'];

			if($z == '1')
				{
				//Set End Date for last completed project!	
				$lastCompletedProject = lastCompletedProject($programmer);
				$nextStart = date("Y-m-d", strtotime($lastCompletedProject . " + 1 weekday"));
				$estimatedEnd = date("Y-m-d", strtotime($nextStart . " + $taskLength weekdays"));
				}
				
			if($z > '1')
				{
				$lastCompletedProject = $estimatedEnd;
				$nextStart = date("Y-m-d", strtotime($lastCompletedProject . " + 1 weekday"));
				$estimatedEnd = date("Y-m-d", strtotime($nextStart . " + $taskLength weekdays"));
				$estimatedEnd = date("Y-m-d", strtotime($estimatedEnd . " 1 weekday"));
				}
		
			echo 'Last Completed Project: ' . $lastCompletedProject . '<br /><br />';

			//Print Task Length and Start & End Dates.
			echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Project Id: ' . $pData['id'] . ' - &nbsp;' . $taskLength . ' days - ' . $nextStart . ' - ' . $estimatedEnd . '<br />'; 
			
			$z++;
			
			echo '<br />';
			}
		}

Open in new window

0
Ray PaseurCommented:
I'm sorry, but I'm just not able to follow the logic.  It seems like I am only looking at a fragment of a script.

I set up this simple example.  The moving parts start at line 150.  You can see it in action on my server here.
http://www.laprbass.com/RAY_temp_t3chguy_4.php

<?php // RAY_temp_t3chguy_4.php 2013-10-18
error_reporting(E_ALL);
echo '<pre>';

// SCHEDULE BASED ON CONSECUTIVE TASKS
// http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28268506.html#a39576941

// CREATE AN ARRAY OF TEST DATA
$test_data_arrays = array
( array( "name" => "Bob" , "days" => "2" )
, array( "name" => "Ray" , "days" => "3" )
, array( "name" => "Jan" , "days" => "4" )
, array( "name" => "Sam" , "days" => "1" )
)
;


// DATABASE CONNECTION AND SELECTION VARIABLES - GET THESE FROM YOUR HOSTING COMPANY
$db_host = "localhost"; // PROBABLY THIS IS OK
$db_name = "??";
$db_user = "??";
$db_word = "??";

// OPEN A CONNECTION TO THE DATA BASE SERVER AND SELECT THE DB
$mysqli = new mysqli($db_host, $db_user, $db_word, $db_name);

// DID THE CONNECT/SELECT WORK OR FAIL?
if ($mysqli->connect_errno)
{
    $err
    = "CONNECT FAIL: "
    . $mysqli->connect_errno
    . ' '
    . $mysqli->connect_error
    ;
    trigger_error($err, E_USER_ERROR);
}

// ACTIVATE THIS TO SHOW WHAT THE DB CONNECTION OBJECT LOOKS LIKE
// var_dump($mysqli);


// CREATING A TABLE FOR OUR TEST DATA
$sql
=
"
CREATE TEMPORARY TABLE my_table
( id   INT NOT NULL AUTO_INCREMENT PRIMARY KEY
, name VARCHAR(24) NOT NULL DEFAULT ''
, days INT NOT NULL DEFAULT 0
)
"
;

// RUN THE QUERY TO CREATE THE TABLE
$res = $mysqli->query($sql);

// IF mysqli::query() RETURNS FALSE, LOG AND SHOW THE ERROR
if (!$res)
{
    $err
    = 'QUERY FAILURE:'
    . ' ERRNO: '
    . $mysqli->errno
    . ' ERROR: '
    . $mysqli->error
    . ' QUERY: '
    . $sql
    ;
    trigger_error($err, E_USER_ERROR);
}

// SHOW THE RESULTS OF THE QUERY
var_dump($res);

// LOADING OUR DATA INTO THE TABLE
foreach ($test_data_arrays as $person)
{
    // ESCAPE THE DATA FOR SAFE USE IN A QUERY
    $safe_n  = $mysqli->real_escape_string($person['name']);
    $safe_d  = $mysqli->real_escape_string($person['days']);

    // CONSTRUCT THE QUERY USING THE ESCAPED VARIABLES
    $sql = "INSERT INTO my_table ( name, days ) VALUES ( '$safe_n', '$safe_d' )";

    // RUN THE QUERY TO INSERT THE ROW
    $res = $mysqli->query($sql);

    // IF mysqli::query() RETURNS FALSE, LOG AND SHOW THE ERROR
    if (!$res)
	{
	    $err
	    = 'QUERY FAILURE:'
	    . ' ERRNO: '
	    . $mysqli->errno
	    . ' ERROR: '
	    . $mysqli->error
	    . ' QUERY: '
	    . $sql
	    ;
	    trigger_error($err, E_USER_ERROR);
	}


    // GET THE AUTO_INCREMENT ID OF THE RECORD JUST INSERTED
    $id  = $mysqli->insert_id;
    echo "MySQLI INSERTED A ROW CONTAINING <b>$safe_n $safe_d</b> WITH AUTO_INCREMENT ID = $id" . PHP_EOL;
}
echo PHP_EOL;

// CONSTRUCT THE QUERY USING THE ESCAPED VARIABLE
$sql = "SELECT name, days FROM my_table ORDER BY id";
$res = $mysqli->query($sql);

// IF mysqli_query() RETURNS FALSE, LOG AND SHOW THE ERROR
if (!$res)
{
    $err
    = 'QUERY FAILURE:'
    . ' ERRNO: '
    . $mysqli->errno
    . ' ERROR: '
    . $mysqli->error
    . ' QUERY: '
    . $sql
    ;
    trigger_error($err, E_USER_ERROR);
}
// IF WE GET THIS FAR, THE QUERY SUCCEEDED AND WE HAVE A RESULT OBJECT IN $res
// AND SO WE CAN NOW USE $res IN OTHER MYSQLI FUNCTIONS

// DETERMINE HOW MANY ROWS OF RESULTS WE GOT
$num     = $res->num_rows;
$num_fmt = number_format($num);
if (!$num)
{
    echo "<br/>QUERY: $sql ";
    echo "<br/>FOUND NO DATA ";
    echo PHP_EOL;
}
else
{
    echo "<br/>QUERY: $sql ";
    echo "<br/>FOUND $num_fmt ROWS OF DATA ";
    echo PHP_EOL;
}
echo PHP_EOL;


// SET THE STARTING DATE FOR THE TASKS
$alpha = date('Y-m-d D', strtotime('Today'));

// COLLECT THE TASK NAMES AND DATES HERE
$out = array();

// ITERATE OVER THE RESULTS SET AS AN OBJECT TO SHOW WHAT WE FOUND
echo PHP_EOL . 'USING MySQLi_Result::Fetch_<i>Object</i>(): ';
echo PHP_EOL;
while ($row = $res->fetch_object())
{
    // COMPUTE END FROM LAST TASK + days -1 TO MAKE DAYS INCLUSIVE
    $lngth = $row->days - 1;
    $omega = date('Y-m-d D', strtotime($alpha . " + $lngth WEEKDAYS"));

    // SAVE THE DATA
    $obj = new StdClass;
    $obj->name = $row->name;
    $obj->days = $row->days;
    $obj->alpha = $alpha;
    $obj->omega = $omega;
    $out[] = $obj;

    // COMPUTE NEXT START DATE
    $alpha = date('Y-m-d D', strtotime($omega . " + 1 WEEKDAY"));
}

// SHOW THE WORK PRODUCT
print_r($out);

Open in new window

HTH, ~Ray
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
t3chguyAuthor Commented:
That certainly helps put me on the right track.  Thank you.  The problem is that the creator of this project doesn't want to store a lot of dates and sort of generate everything dynamically, which is what complicates this a lot.
0
Ray PaseurCommented:
... complicates this a lot.
You can say that again!  Thanks for the points and good luck with the project, ~Ray
0
t3chguyAuthor Commented:
Thanks, I'll need it!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.