Results 1 to 3 of 3

Thread: next,prev link problems

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2007
    Posts
    43

    next,prev link problems

    i am working on a calendar and i have it set up so that you can cyclye throuhg the months and i want it to change the year as well like if its january of 2007 and you hit prev i want it to become december of 2006.

    i have the calendar working completely with the next and prev links working to a point it changes the month ok and i managed to get it to chnage the year when you go from december to january, however for some reason it will not change the year when i go from january to december, even though i used the exact same method to accomplish both.

    this is the code i used to accomplish the month switch
    PHP Code:
    if(empty($_GET['month'])){
        
    $today1 getdate(); 
            
    $month=$today1['mon'];
    }else{
    $month=$_GET['month'];}
                
    if(empty(
    $_GET['year'])){
        
    $today2 getdate(); 
        
    $year=$today2['year'];
    }else{
    $year=$_GET['year'];}
                
    if(
    $month==0){
        
    $month=12;
        
    $year--;
    }
                
    if(
    $month==13){
        
    $month=1;
        
    $year++;
    }
                
    fWriteCalendar(fGetEvents(),$month,$year); 
    this is the part of the calendar write function that handles it

    PHP Code:
    function fWriteCalendar($vResults,$vMonth,$vYear){

    $today  getdate();
    $temp1 getdate(mktime(0,0,0,$vMonth,1,$vYear));
    $temp2 getdate(mktime(0,0,0,$vMonth+1,0,$vYear));
    $introoffset $temp1['wday'];
    $closeoffset $temp2['wday'];
    $days=$temp2['mday'];
    $month=$temp1['month'];
    $prevmonth  $vMonth-1;
    $nextmonth  $vMonth+1;
     
    $vCalendar'
    <a href="calendar.php?month='
    .$prevmonth.'&year='.$year.'"><<</a>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    Calender of Events for '
    .$month.'-'.$vYear.
    '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <a href="calendar.php?month='
    .$nextmonth.'&year='.$year.'">>></a>; 
    if anyone can help me figure out why the year will not decrease from january to december it would help alot.

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: next,prev link problems

    you should let the date() function figure out everything for you instead. unix timestamps are wonderful. it's much more simple, too. example:

    PHP Code:
    <?php
      
    //get the month. it is held in $_GET['date'] if there is a previous month
      
    $this_month = (isset($_GET['date']) && is_numeric($_GET['date'])) ? $_GET['date'] : mktime(000date("n"), 1date("Y"));
      
    //next month = this month + 1
      
    $next_month mktime(000date("n"$this_month) + 11date("Y"$this_month));
      
    //previous month = this month - 1
      
    $prev_month mktime(000date("n"$this_month) - 11date("Y"$this_month));
    ?>
    <a href="./calendar.php?date=<?php echo $prev_month?>">&lt;&lt; <?php echo date("F, Y"$prev_month); ?></a> - <strong><?php echo date("F, Y"$this_month); ?></strong> - <a href="./calendar.php?date=<?php echo $next_month?>">&gt;&gt; <?php echo date("F, Y"$next_month); ?></a>
    see it in action here. you will lose the ability for your users to enter in custom dates via the query string (at least with my version), but you can easily remedy this by not using unix timestamps in the query string and instead only build them for use within the program using mktime().

    hope that helps.

  3. #3
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: next,prev link problems

    Code:
    66.249.72.138 - - [19/Apr/2007:23:36:21 -0600] "GET /php/calendar.php?date=1143874800 HTTP/1.1" 200 162 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
    66.249.72.138 - - [20/Apr/2007:01:30:35 -0600] "GET /robots.txt HTTP/1.1" 404 1076 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
    66.249.72.138 - - [20/Apr/2007:01:30:35 -0600] "GET /php/calendar.php?date=1141196400 HTTP/1.1" 200 167 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
    66.249.72.138 - - [20/Apr/2007:03:20:28 -0600] "GET /php/calendar.php?date=1138777200 HTTP/1.1" 200 169 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
    66.249.72.105 - - [20/Apr/2007:06:10:01 -0600] "GET /php/calendar.php?date=1201849200 HTTP/1.1" 200 169 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
    66.249.72.105 - - [20/Apr/2007:06:35:01 -0600] "GET /php/calendar.php?date=1136098800 HTTP/1.1" 200 172 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
    google was indexing my test thing. and it still is. guess I should be adding a nofollow value to links like that from now on @_@. hehe. fixed!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width