next three months

Re: next three months

Postby MrRundog » Fri Apr 11, 2008 3:10 pm

Well, I'm thinking - move forward 6 months - but only ever show 6 months at one time -
I will most likely use a previous <-> forward link rather than dropdown.

Andy
User avatar
MrRundog
 
Posts: 14
Joined: Fri Apr 11, 2008 12:57 pm

Re: next three months

Postby chris » Fri Apr 11, 2008 3:28 pm

OK,
Step 1:
Detect and define new vars
Add this towards the beginning of the code to catch the data sent by the links or to define the defaults:
Code: Select all
if((isset($_REQUEST["year_month"])) && (!empty($_REQUEST["year_month"])) ){
   $date_bits=explode("-",$_REQUEST["year_month"]);   #   0=year, 1=month
   define("START_YEAR",    $date_bits[0]);
   define("START_MONTH",   $date_bits[1]);
   //$this_block   =   $date_bits[2];
}else{
   define("START_YEAR",   date('Y'));
   define("START_MONTH",   date('m'));
}

Step 2:
NEW MONTH LOOP
Replace the code you mentioned before (including the "else" section) with this:
Code: Select all
$the_months   =   array();

$j   =   0;
$this_year   =   START_YEAR;
$this_month   =   START_MONTH;

$num_months_shown=0;
while($num_months_shown<MONTHS_TO_SHOW){
   //   start new year and reset month numbers
   if($this_month>12){
      $this_month   =   $this_month-12;                  #   remove full 12 months from cal num
      $this_year   =   $this_year+1;                  #   add 1 to current year
   }
   $this_month=sprintf("%02s",$this_month);            #   add 0 if less that 10
   $the_months[$this_month]=array("year"=>$this_year,"month"=>$this_month);
   ++$num_months_shown;
   ++$this_month;
}

Step 3:
Define previous and next strat months
After the last bit and BEFORE you create the links, add this:
Code: Select all
//   define LAST block - START
$last_month_start   =    (START_MONTH-MONTHS_TO_SHOW);   #   remove months_to_show x 2 to go back this block and then 1 more
$last_year_start   =   START_YEAR;
if($last_month_start<0){
   $last_month_start=$last_month_start+12;
   --$last_year_start;
}
$last_month_start=sprintf("%02s",$last_month_start);

//   define NEXT block - START
$next_month_start   =    $this_month;   #   just use MONTH number that the loop has ended on
$next_year_start   =   $this_year;      #   just use YEAR number that the loop has ended on
if($next_month_start>12){
   $next_month_start=$next_month_start-12;
   ++$next_year_start;
}

$next_month_start=sprintf("%02s",$next_month_start);

step 5
THE LINKS
Now you can create the links of your choice, the url will need to look something like this:
Code: Select all
<a href="calendar.php?id_item=<?php echo ID_ITEM; ?>&year_month=<?php echo $last_year_start; ?>-<?php echo $last_month_start; ?>">prev</a>
<a href="calendar.php?id_item=<?php echo ID_ITEM; ?>&year_month=<?php echo $next_year_start; ?>-<?php echo $next_month_start; ?>">next</a>


Well, I think that that is it - I hope I haven't missed anything ;)

Let me know how it goes :)

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

Re: next three months

Postby MrRundog » Fri Apr 11, 2008 4:08 pm

Superb - Worked first time :D Thanks for the extreemly quick response

Andy
User avatar
MrRundog
 
Posts: 14
Joined: Fri Apr 11, 2008 12:57 pm

Re: next three months

Postby adh2k1 » Wed May 28, 2008 8:38 pm

Is there anyway to see this added to the default file, I kept trying but would always break the calendar showing up. I want to use the link function, but am unsure where the new call to draw the calendar is.
adh2k1
 
Posts: 2
Joined: Tue May 27, 2008 11:55 pm

Re: next three months

Postby chris » Wed May 28, 2008 8:50 pm

What errors are you getting?
I would have thought that the steps defined in this thread where pretty straight forward, at least I tried to explain it as best I could.

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

Re: next three months

Postby WimDC » Mon Oct 13, 2008 1:39 pm

Hello,

I'm new in this forum and I'm trying the code for the "prev" - "next" option as mentioned before.
BUT... everything works (I can see the calendar, I can mark some dates as booked) EXCEPT the "prev" en "next".
Then I get an error "page not found".

See http://www.dexiabruggetillegem.be/avail ... _nieuw.php
(also see php file in attachment)

I suppose I have put some code on the wrong place, but I can't find where.
Can someone help me ?
Attachments
index_nieuw.zip
not working index_nieuw.php
(2.82 KiB) Downloaded 255 times
WimDC
 
Posts: 3
Joined: Mon Oct 13, 2008 1:28 pm

Re: next three months

Postby chris » Mon Oct 13, 2008 2:37 pm

Hi there and welcome to the forum :)

A quick check on your page (I haven't actually looked at the zip file) shows that you aren't send the php variables properly (at all)
You have this:
Code: Select all
<a href="calendar.php?id_item=<?php echo ID_ITEM; ?>&year_month=<?php echo $last_year_start; ?>-<?php echo $last_month_start; ?>">prev</a>
<a href="calendar.php?id_item=<?php echo ID_ITEM; ?>&year_month=<?php echo $next_year_start; ?>-<?php echo $next_month_start; ?>">next</a>

I suspect that this means that you are trying to open new php tags in code that is already within php (if you see what I mean)
ie the links are already within an "echo".
You just need to replace the <?php echo and ;?> with '. and .' within these links so that it looks like this:
Code: Select all
<a href="calendar.php?id_item='.ID_ITEM.'&year_month='.$last_year_start.'-'.$last_month_start.'">prev</a>
<a href="calendar.php?id_item='.ID_ITEM.'&year_month='.$next_year_start.'-'.$next_month_start.'">next</a>

Now, I can't say that is your only problem, but until that bit is sorted out it is impossible to tell.

Hope this helps,

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

Re: next three months

Postby WimDC » Mon Oct 13, 2008 2:53 pm

Hello,

thanks for the reply, but after changing the code, the "prev" and "next" still doesn't work.
WimDC
 
Posts: 3
Joined: Mon Oct 13, 2008 1:28 pm

Re: next three months

Postby chris » Mon Oct 13, 2008 3:42 pm

Right, not check the php page that you are linking to.
You have this as the page:calendar.php
But is suspect that it should be this: index_nieuw.php

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

Re: next three months

Postby WimDC » Mon Oct 13, 2008 4:46 pm

Yes, I did it.
Sorry... you did it !

Thanks for helping!

Wim
WimDC
 
Posts: 3
Joined: Mon Oct 13, 2008 1:28 pm

PreviousNext

Return to General

Who is online

Users browsing this forum: No registered users and 2 guests

cron