Show specific months

Show specific months

Postby ile » Wed Feb 06, 2008 1:48 pm

Hello :)
First, i would like to thank you for this great script :)
I want to show only 4 months (for example), starting from May...
I set:
$cur_month = 05;
But then i don't know how to limit the show to only 4 months... i've tried changing numbers in the "for loops" but no success.
I've tried to change this
for($k=$cur_month; $k<=12; $k++){
into this:
for($k=$cur_month; $k<=4; $k++){
but then first shown month is may 2008, and then starts next year with january 2009.

Here in top of the page is example of what i need :)
http://www.cbolson.com/code/availability-calendar/

Any help would be apreaciated

Thanks,
Ile
ile
 
Posts: 3
Joined: Wed Feb 06, 2008 1:39 pm

Re: Show specific months

Postby chris » Sun Feb 10, 2008 7:05 pm

Hi there and welcome to the forum.
Sorry for not answering earlier - I need to figure out if it is possibe to get this forum to send me an email every time a new topic is started :lol: .

I must mention that this script was more focused on the ajax aspect rather than the php and, with out a doubt the php date code could be far improved.

That said, I think that this mod will solve your problem.

Find the lines:
Code: Select all
$j=0;
for($k=$cur_month; $k<=12; $k++){
   $this_month=sprintf("%02s",$k);
   $the_months[$this_month]=array("year"=>$cur_year,"month"=>$this_month);
   $j++;
}

//   check if all the months are shown
if($j<12){
   //   add next year months
   for($k=1;$k<$cur_month;$k++){
      $this_month=sprintf("%02s",$k);
      $the_months[$this_month]=array("year"=>($cur_year+1),"month"=>$this_month);
   }
}

and replace with this:
Code: Select all
$total_months_to_show=5; # set the number of months to show from now
$k=$cur_year;
$j=0;
while($j<$total_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++;
   }
}


That should work for you ;)

Chris
User avatar
chris
Site Admin
 
Posts: 1089
Joined: Mon Dec 17, 2007 7:42 pm
Location: Málaga, Spain

Re: Show specific months

Postby ile » Wed Feb 13, 2008 9:37 pm

thanks for reply, unfortunately the original code of script i have does not contain a code from your post.
i do not have "$j=0" in the part of code that you cut.

i have this:

Code: Select all
$the_months=array();
$total_months=1;
for($k=$cur_month; $k<=12; $k++){
   $this_month=sprintf("%02s",$k);
   $the_months[$this_month]=array("year"=>$cur_year,"month"=>$this_month);
   $total_months++;
}
//   check if all the months are shown
if($total_months<12){
   //   add next year months
   for($k=1;$k<$cur_month;$k++){
      $this_month=sprintf("%02s",$k);
      $the_months[$this_month]=array("year"=>($cur_year+1),"month"=>$this_month);
   }
}
ile
 
Posts: 3
Joined: Wed Feb 06, 2008 1:39 pm

Re: Show specific months

Postby ile » Wed Feb 13, 2008 9:49 pm

now i've tried this:

Code: Select all
$j=0;
for($k=$cur_month; $k<=12; $k++){
   $this_month=sprintf("%02s",$k);
   $the_months[$this_month]=array("year"=>$cur_year,"month"=>$this_month);
   $j++;
}

//   check if all the months are shown
if($j<12){
   //   add next year months
   for($k=1;$k<$cur_month;$k++){
      $this_month=sprintf("%02s",$k);
      $the_months[$this_month]=array("year"=>($cur_year+1),"month"=>$this_month);
   }
}


and it works also fine for all months, but solution for specific months doesnt work.
Number of months is listed correctly but there are no month names and days listed (numbers)
ile
 
Posts: 3
Joined: Wed Feb 06, 2008 1:39 pm

Re: Show specific months

Postby chris » Thu Feb 14, 2008 1:06 am

try replacing what you have just posted with my new bit of code as per my last post.
ie:
Code: Select all
    $total_months_to_show=5; # set the number of months to show from now
    $k=$cur_year;
    $j=0;
    while($j<$total_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++;
       }
    }


Chris
User avatar
chris
Site Admin
 
Posts: 1089
Joined: Mon Dec 17, 2007 7:42 pm
Location: Málaga, Spain


Return to General

Who is online

Users browsing this forum: No registered users and 0 guests

cron