Jump to content

[SOLVED] isEnrolled()


jrm

Recommended Posts

I have been working on this problem for about a month and cannot figure it out.  I had it working with MS Access for selecting one month, but I need to convert it over to php.

 

So I start with this function:

function EnrolledBetween($StartDTG, $StopDTG)
{
    include "Connection.php";
    
    $dropquery = "Drop Temporary Table If Exists test.t_CadetsDates;";
    $dropresults = mysql_query($dropquery, $link) or die("\n<p> Could not run query : " . $dropquery . " : " . mysql_error());
    $createquery = "Create Temporary Table test.t_CadetsDates 
                    Select Cadets.CadetID, Cadets.Last,
                      (Select DTG From Cadets_be.CadetsDates Where SDID=11 and Cadets.CadetID = CadetsDates.CadetID) as DoEntry,
                      (Select DTG From Cadets_be.CadetsDates Where SDID=6 and Cadets.CadetID = CadetsDates.CadetID) as DoExit
                    From Cadets_be.Cadets
                    Where Cadets.Last<>'Test'
                    Order by Last, First, Middle;";
    $result = mysql_query($createquery, $link) or die("\n<p> Could not run query : " . $createquery . " : " . mysql_error());
    
    $query = "Select CadetID, DoEntry, DoExit From test.t_CadetsDates";
    $result = mysql_query($query, $link) or die("\n<p>Could not run query : " . $query . " : " . mysql_error());
    if(mysql_num_rows($result)==0)
    {
        $CadetList = NULL;
    }
    else
    {
        for($j = 0; $j <= mysql_num_rows($result)-1; $j++)
        {
            $newrow = mysql_fetch_array($result,MYSQL_NUM);
            for($m = 0; $m <= mysql_num_fields($result)-1 ; $m++)
            {
                $CadetList[$j][mysql_field_name($result, $m)] = $newrow[$m];
            }
        }
    }
    
    if(is_array($CadetList))
    {
        //print_r($CadetList);
        $results = isEnrolled($CadetList,$StartDTG, $StopDTG);
        return $CadetList;
    }
    else
    {
        //echo "\n<p>$CadetList</p>";
        return "N/A";
    }
}

 

Which basically makes a pivot table from my Cadets_be.Cadets, Cadets_be.CadetsDates tables.  And sends it to another function ( which I can not figure out) to put the cadets that were enrolled between the two dates into is Enrolled[].  The problem is that it is not a simple isbetween($StartDateTime, $StopDateTime).  There are four dates to deal with.  Can anybody direct me onto the right path?

 

Link to comment
https://forums.phpfreaks.com/topic/143558-solved-isenrolled/
Share on other sites

Solved it with this function:

function isEnrolled($CadetRoster, $StartDTG, $StopDTG)
{
    $timeframe = 60*60*24*240;
    for($i = 0; $i <= count($CadetRoster) - 1; $i++)
    {
        $DoEntry = strtotime($CadetRoster[$i]["DoEntry"]);
        $DoExit = (!empty($CadetRoster[$i]["DoExit"]) ? strtotime($CadetRoster[$i]["DoExit"]) : $DoEntry + $timeframe);
        if(($DoEntry <= $StopDTG) == True)
        {
            if(($StartDTG <= $DoExit) == True)
            {
                $Enrolled[] = $CadetRoster[$i];
            } 
        }
    }   
    return $Enrolled;
}

Link to comment
https://forums.phpfreaks.com/topic/143558-solved-isenrolled/#findComment-753304
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.