Hej
Jeg har siddet fast i et par dage med dette problem og ved simpelthen ikke hvordan jeg skal løse det.
jeg skal have min navigation til at skifte år efter hvert 4. kvartal, er der en venlig sjæl der vil give et hint ?.
- <?php
- // GET QUARTER FUNCTION
- function get_kvt($month){
- $q = 0;
- switch ($month) {
- case '1':
- case '2':
- case '3':
- $q = 1;
- break;
- case '4':
- case '5':
- case '6':
- $q = 2;
- break;
- case '7':
- case '8':
- case '9':
- $q = 3;
- break;
- case '10':
- case '11':
- case '12':
- $q = 4;
- break;
- }
-
- return $q;
- }
-
- // if the year is set in the URL then give it to me, else give me the real year
- $current_year = (isset($_GET['year'])? $_GET['year']: date("Y"));
- $next_year = $current_year + 1;
- $prev_year = $current_year -1;
- $first_year = 2010;
- $last_year = 2030;
-
- // if the quarter is set in the URL then give it to me, else give me the quarter from my function year
- $current_quarter = (isset($_GET['q'])? $_GET['q']: get_kvt(date("n")));
- $next_quarter = $current_quarter + 1;
- $prev_quarter = $current_quarter -1;
- $first_quarter = 1;
- $last_quarter = 4;
-
-
- // if prev quarter is less then 1 then change the quarter to 4
- if ($prev_quarter < $first_quarter) {
- $prev_quarter = $last_quarter;
- if ($first_quarter == 1) {
- $current_year = $next_year;
- }
-
- }
- // if prev quarter is greater then 4 then change the quarter to 1
- if ($next_quarter > $last_quarter){
- $next_quarter = $first_quarter;
- if ($last_quarter == 4) {
- $current_year = $prev_year;
- }
-
- }
-
-
-
- // prevent exceed the first and last year
- if($current_year < $first_year) {
- $current_year = $first_year;
- }
- if($current_year > $last_year) {
- $current_year = $last_year;
- }
- // DEBUG PREVIEW
- echo $prev_quarter . " <--Prev Q | Next Q --> " . $next_quarter . "<br>";
- echo $prev_year . " <--Prev Y | Next Y --> " . $next_year . "<br>";
-
- // NAVIGATION
- echo "
- <a href='nav.php?q=$prev_quarter&y=$current_year'>Previous</a>
- <a href='nav.php?q=$next_quarter&y=$current_year'>Next</a>
-
- ";
-
-
- // OUTPUT
- echo "<br>current year <h2>(" . $current_year . ")</h2>";
- echo "<h2>current quarter (" . $current_quarter . ")</h2>";
-
- ?>