I need to do create a multi-dimensional array with name and date. Both are executed in different query then joined together. The end product should be something like this.
Now I'm almost there however, there's just something that I couldn't get to work.
This is the part where I process the query.
And this is the function.
PHP Code:
function getDateforMonth($date, $month) {
global $newDate;
foreach ($date as $dateValue) {
if (substr($dateValue, 5, 2) == $month) {
// Store the correct month a new array
$newDate .= $dateValue . ", ";
}
}
return $newDate;
}
// Get a list of available date of each personnel and sort them accordingly
// $personnel :: Official name
// $month :: Month of Duty
function availableDate($personnel, $month) {
$DB = NewADOConnection('mysql');
$DB->Connect(@$server, @$user, @$pwd, @$db);
$query = "SELECT * FROM dms_personnel WHERE personnel_name = '$personnel'";
$rs = $DB->Execute($query);
$arr = $rs->FetchRow();
$id = $arr['id'];
$coy = $arr['personnel_company'];
// Base on the ID, check with the individual schedule
$queryID = "SELECT individual_schedule_date FROM dms_individual_schedule WHERE personnel_id = $id";
$rsID = $DB->Execute($queryID);
$arrID = $rsID->FetchRow();
// Remove the last 2 character (, ) from the string using substr
// Use explode to convert string into array
$date = explode(', ', substr($arrID['individual_schedule_date'], 0, -2));
// Get the available date for the date instead of the whole schedule
$new = "";
$new = getDateforMonth($date, $month);
echo "<pre>";
print_r(explode(", ", substr($new,0,-2)));
echo "</pre>";
}
But the result that I got was..
By right, the date for the respective ID should be.
I'm yet to do into the multi-dimension array and I have problem like the data keep adding on the previous ones. I know somewhere I have to clear the list first before going into the loop. But I just can't get it. Can someone help me with it?