View Single Post
  #11 (permalink)  
Old 04-23-09, 01:12 AM
Nikas Nikas is offline
Coding Addict
 
Join Date: Jun 2005
Location: Singapore
Posts: 377
Thanks: 0
Thanked 1 Time in 1 Post
Ok. I think I have to change to another way. Is it possible to make another dimension in the array?

I have changed the function a little and add in other dates into the array. I have made a comment "// Newly Added".

PHP Code:

function unavailableDates(&$DB$personnelId$month$coy) {


        
// Base on the ID, check with the individual schedule
        
$queryID "SELECT individual_schedule_date FROM dms_individual_schedule WHERE personnel_id = $personnelId";
        
$rsID $DB->Execute($queryID);
        
$arrID $rsID->FetchRow();

        
// Remove the last 2 character (, ) from the string using substr
        // Use explode to convert string into array
        
$dates explode(', 'substr($arrID['individual_schedule_date'], 0, -2));
    
    
// Base on the Coy, check with the company schedule
       // Newly Added
    
$queryCoy "SELECT schedule_training_date FROM dms_company_schedule WHERE schedule_company = '$coy' AND schedule_training_date != ''";
    
$rsCoy $DB->Execute($queryCoy);
    
$arrCoy $rsCoy->FetchRow();
    
    
$datesCoy explode(', 'substr($arrCoy['schedule_training_date'], 0, -2));
    
        
// Get the available dates for the specified month instead of the whole schedule
        
$availableDates = array();
        foreach (
$dates as $dateValue) {
            if (
substr($dateValue52) == $month) {
                
$availableDates[] = $dateValue;
            }
        }
    
    
// Get the available dates for company for the specified month instead of the whole schedule
       // Newly added
        
$availableCoyDates = array();
        foreach (
$datesCoy as $dateValueCoy) {
            if (
substr($dateValueCoy52) == $month) {
                
$availableCoyDates[] = $dateValueCoy;
            }
        }
    
// Combine both the dates and place into one array
    
$availableDates_merge array_merge($availableDates$availableCoyDates);
    
        return 
$availableDates_merge;
    } 
Thus, currently, the result is

Code:
Array
(
    [Tan Ah Lian] => Array
        (
            [0] => 2009-04-20
            [1] => 2009-04-21
            [2] => 2009-04-22
            [3] => 2009-04-24
            [4] => 2009-04-25
        )

    [Joseph Gan] => Array
        (
            [0] => 2009-04-04
            [1] => 2009-04-05
            [2] => 2009-04-06
        )
)
Example, under the name "Tan Ah Lian". It's inclusive of two date that uses array_merge to combine the dates from two query.

Could I do it in a way that separate it? Like the below.

Code:
Array 
(
	[Tan Ah Lian] => Array
	    (
		[Individual Date] => Array
		    (
			[0] => 2009-04-20
			[1] => 2009-04-21
			[2] => 2009-04-22
		    )
		[Company Date] => Array
		    (
			[0] => 2009-04-24
			[1] => 2009-04-25
		    )
	    )
)
Reply With Quote