Page 1 of 1

Displaying more than 12 months

PostPosted: Tue May 20, 2008 3:23 pm
by lc10
Hello,

New to the forum and this amazing script.

I'm currently working on a redesign for a Lanzarote apartment rental website, http://www.lascoronas10.co.uk, and am integrating the availability calendar. I have currently set it up to test but am having trouble displaying more than 12 months.

The display of a rolling 12 months is great, but I would like to be able to display the months to the end of this current year and all 12 months of the following year. Is this possible?

I know I need to change the code:
Code: Select all
//    define number months to show
if(isset($_REQUEST["months_to_show"]))    define("MONTHS_TO_SHOW",   $_REQUEST["months_to_show"]);
else                           define("MONTHS_TO_SHOW",   12);


Changing the 12 to an 18 for example doesn't work, can I achieve what I am looking to do?

Re: Displaying more than 12 months

PostPosted: Tue May 20, 2008 6:32 pm
by chris
Hi there, welcome to the forum and thanks for you comments.

I have tried and failed to do what you are saying - I have never managed to display more than 12 months without adding masses of php conditions, something that I really wanted to try and avoid (there are too many in there as it is) I decided that 12 months was probably (more than) enough for most users so have given up trying.

If you really really need this and can't work it out I will take another look - maybe a fresh look and approach might show me the answer but I really wonder if it is really worth it - wouldn't showing 12 months with a select box or "next" button be enough?

Chris

Re: Displaying more than 12 months

PostPosted: Wed May 21, 2008 3:09 pm
by lc10
Hi Chris,

Managed to work it out...

I changed the following code block
Code: Select all
while($j<MONTHS_TO_SHOW){
   $this_month=sprintf("%02s",$k);
   $the_months[$this_month]=array("year"=>$cur_year,"month"=>$this_month);
   $j++;
   if($k==12){
      //   start new year and reset counter to 1 (jan)
      $cur_year=$cur_year+1;
      $k=1;
   }else{
      $k++;
   }
}


to this
Code: Select all
while($j<MONTHS_TO_SHOW){
   $this_month=sprintf("%02s",$k);
   $the_months[$j]=array("year"=>$cur_year,"month"=>$this_month);
   $j++;
   if($k==12){
      //   start new year and reset counter to 1 (jan)
      $cur_year=$cur_year+1;
      $k=1;
   }else{
      $k++;
   }
}


Effectively changing the line:
Code: Select all
$the_months[$j]=array("year"=>$cur_year,"month"=>$this_month);
and amending the "$the_months[$this_month] to $the_months[$j]". This allows the calendar to loop through the counter of $j and not the months in the year, preventing the overwriting of the months due to the original max of 12 months in the loop.

I then just needed to change the months_to_show variable to the number of months I wanted and not 12.

Hope this makes sense.

Chris

Re: Displaying more than 12 months

PostPosted: Wed May 21, 2008 10:22 pm
by chris
hmmm, that clearly works, thanks :)

though there must be some reason as to why it didn't work for me..... :?: maybe I was trying it on an adapted version - I have made so many adaptions now it is hard to keep track :(

Chris

Re: Displaying more than 12 months

PostPosted: Wed Jun 11, 2008 3:42 pm
by greatness
thanks for that .. works a treat