I have a chart that displays weekly visits to the site, the values are in the format "d M Y" and data will be returned from the database.
At current state only display labels for days which I got data (eg. August 1, 2016 and today ).
I would also return the next days in each label (for each day of the week), but keep in mind the current day of the week (eg. if is Wednesday must return August 3, 2016, if is Thursday return August 4, 2016 etc.) relative to the current day of the week, so if it's Monday (and I have data) returns the value from the database, if it's Tuesday (today) returns data from the database, but if it's Wednesday it is calculated that We got Third day of the week so adds +1 to the current date, if it will be on Thursday adds +2 etc. I hope I have explained much as possible as a result I'm trying to reach
I've tried to make a PHP switch but can't reach a result using this, and I'm thinking my logic is totally wrong.
function get_day($date,$daynum) {
$dayofweek = date("w",strtotime($date));
switch ($daynum) {
case '1':
if ($date == NULL) {
$current = date('d M Y',strtotime("$date +1 day"));
} elseif ($date == date("d M Y")) {
$current = 'Oggi';
} else {
$current = date("d M Y",strtotime($date));
}
break;
case '2':
if ($date == NULL) {
$current = date('d M Y',strtotime("$date +2 day"));
} elseif ($date == date("d M Y")) {
$current = 'Oggi';
} else {
$current = date("d M Y",strtotime($date));
}
break;
case '3':
if ($date == NULL) {
$current = date('d M Y',strtotime("$date +3 day"));
} elseif ($date == date("d M Y")) {
$current = 'Oggi';
} else {
$current = date("d M Y",strtotime($date));
}
break;
case '4':
if ($date == NULL) {
$current = date('d M Y',strtotime("$date +4 day"));
} elseif ($date == date("d M Y")) {
$current = 'Oggi';
} else {
$current = date("d M Y",strtotime($date));
}
break;
case '5':
if ($date == NULL) {
$current = date('d M Y',strtotime("$date +5 day"));
} elseif ($date == date("d M Y")) {
$current = 'Oggi';
} else {
$current = date("d M Y",strtotime($date));
}
break;
case '6':
if ($date == NULL) {
$current = date('d M Y',strtotime("$date +6 day"));
} elseif ($date == date("d M Y")) {
$current = 'Oggi';
} else {
$current = date("d M Y",strtotime($date));
}
break;
case '7':
if ($date == NULL) {
$current = date('d M Y', strtotime("$date +7 day"));
} elseif ($date == date("d M Y")) {
$current = 'Oggi';
} else {
$current = date("d M Y",strtotime($date));
}
break;
}
return $current;
}
I'm calling this using
get_day($siteViewsThisWeek[0][1],'1');
get_day($siteViewsThisWeek[1][1],'2');
get_day($siteViewsThisWeek[2][1],'3');
[...]
Thanks to all who can help.