Sortering på dato med identiske keys
Hej,Jeg trækker datoer ud fra to databaser (med fødselsdage og møder), disse kan falde på samme dato. Hvordan får jeg dem vist?
Følgende haves:
$this_year = date("Y");
$next_year = date('Y', strtotime('+1 year'));
$interval_date = date('Y-m-d', strtotime(date("Y-m-d"). ' +5 month'));
$qry_cal = "
SELECT birthday AS sorter, birthday, NULL AS date, first AS beskr FROM all_users
UNION ALL
SELECT date AS sorter, NULL AS birthday, date, description AS beskr FROM calender_".$this_year." WHERE date > CURDATE()
UNION ALL
SELECT date AS sorter, NULL AS birthday, date, description AS beskr FROM calender_".$next_year." WHERE date > CURDATE()
ORDER BY MONTH(sorter), DAY(sorter), YEAR(sorter) ASC";
$result_cal = mysqli_query($dbc, $qry_cal);
$date2 = array();
while ($row = mysqli_fetch_array($result_cal)) {
if (!empty($row['birthday'])) {
$now = time();
$dob = strtotime($row['birthday']);
$birthd = explode("-", $row['birthday']);
$dob_thisyear = date("Y").'-'.$birthd[1].'-'.$birthd[2];
$difference = $now - $dob;
$age = floor($difference / 31556926)+1;
$day = date("d-m-Y", strtotime($row['birthday']));
if ($dob_thisyear >= date("Y-m-d")) {
$dob_next = $dob_thisyear;
} else {
$year_next = date('Y', strtotime('+1 year'));
$dob_next = $year_next.'-'.$birthd[1].'-'.$birthd[2];
}
if ($dob_next <= $interval_date) {
$date2[$dob_next] = ' <img src="danneb.png" height="20" width="20"> '.$row['beskr'].' '.($age).' år';
}
}
if (!empty($row['date'])) {
if ($row['date'] <= $interval_date) {
$date2[$row['date']] = ' <img src="calendar.png" height="20" width="20"> '.$row['beskr'];
}
}
}
ksort($date2);
foreach ($date2 as $d => $b) {
echo $d.'-'.$b.'<br>';
}