PHP Classes

Get month and year values

Recommend this page to a friend!

      Active Calendar  >  All threads  >  Get month and year values  >  (Un) Subscribe thread alerts  
Subject:Get month and year values
Summary:Request for help on how to get date values from class
Messages:6
Author:Ragnvald Larsen
Date:2005-02-24 19:06:49
Update:2005-02-26 01:02:23
 

  1. Get month and year values   Reply   Report abuse  
Picture of Ragnvald Larsen Ragnvald Larsen - 2005-02-24 19:06:49
I am using the Active Calendar class to display a month with month-navigation, year enableYearNav, etc.. This works nicely. I even manage to insert projects on certain dates by using this functionality:

$cal->setEventContent($project_year, $project_month, $project_day ,$info_string, $linkurl."?project_id=".$res_row_projects[0]);

On the same page I also plan present a list of the 5 former and 5 future incidents regadless on when they happen (inside or outside the published month).

How do I get information from within the class to use for SQL queries to produce the former/future incidents list?


  2. Re: Get month and year values   Reply   Report abuse  
Picture of Giorgos Giorgos - 2005-02-25 01:20:19 - In reply to message 1 from Ragnvald Larsen
If I understand you well, you would like to know on which date (year, month and day value) is each generated calendar (if a user is navigating the calendar), so that you can use these values in your SQL queries and produce the required lists.

Well, each calendar is generated first with the class constructor:
$cal=new activeCalendar([$yearID,$monthID,$dayID]), where the optional parameters set the date, on which a calendar is generated (if they are set false, the calendar of the current date will be generated).

The calendar navigation and day links have automatically the wanted parameters and values. For example: if a month calendar is generated for February 2005, the forward navigation control link would be something like:
your_page.php?yearID=2005$monthID=3 and the previous navigation control something like: your_page.php?yearID=2005$monthID=1

You can generate the next calendar by extracting these url parameters and passing them to the class constructor (see examples too):
extract($_GET);
$cal=new activeCalendar($yearID,$monthID,$dayID);

So, I suppose you have the wanted date to create your SQL, by just extracting the url date variables.

You could use the 'private' class variables $cal->actyear (contains the calendar year), $cal->actmonth (contains the calendar month), $cal->actday (contains the calendar day) as well but I would not recommend it.

Please tell me, if this is what you were looking for or if I have not understood your question.

  3. Re: Get month and year values   Reply   Report abuse  
Picture of Ragnvald Larsen Ragnvald Larsen - 2005-02-25 08:22:03 - In reply to message 2 from Giorgos
Giorgos, your advice was "right on". Unfortunately getting the extracted dates is not all that easy. I tried this:

- - - - -
extract($_GET);

$cal=new activeCalendar($yearID,$monthID,$dayID);

$datestring = $yearID."-".$monthID."-".$dayID"." 00:00:00";

echo $datestring;
- - - - -

The two last lines were mine. Didnt help much. Returned string was:

"-- 00:00:00"

I tried pulling out the string contents by placing my two lines after extract($_GET). Didnt help any. Variables are empty, so I am stuck if I do not want to mess with the class variables.

  4. Re: Get month and year values   Reply   Report abuse  
Picture of Giorgos Giorgos - 2005-02-25 12:26:59 - In reply to message 3 from Ragnvald Larsen
How does the generated URL looks like, when navigating the calendar? It should be something like: your_page?yearID=2005&monthID=3
If the URL has a structure like the one above, try something like:

<?php
require_once("activecalendar.php");
$yearID=date("Y"); // current year
$monthID=date("n"); // current month
$dayID=false;
// this time, do not use extract($_GET)
if (isset($_GET['yearID'])) $yearID=$_GET['yearID'];
if (isset($_GET['monthID'])) $monthID=$_GET['monthID'];
if (isset($_GET['dayID'])) $dayID=$_GET['dayID'];
$cal=new activeCalendar($yearID,$monthID,$dayID);
$cal->enableMonthNav();
print $cal->showMonth();
print "<br />";
//display some day of your choice insted of nothing
if ($dayID==false) $dayID=25;
print $yearID."-".$monthID."-".$dayID."- 00:00:00";
?>

Inform me about your progress...

  5. Re: Get month and year values   Reply   Report abuse  
Picture of Ragnvald Larsen Ragnvald Larsen - 2005-02-25 19:56:27 - In reply to message 4 from Giorgos
It worked now, thanks to your advice. By using the following it worked:

if (isset($_GET['yearID'])) $yearID=$_GET['yearID'];
if (isset($_GET['monthID'])) $monthID=$_GET['monthID'];
if (isset($_GET['dayID'])) $dayID=$_GET['dayID'];

I really do not know why, but I guess the function used in the example somewhat disturbed the contents of the variables from the former page (ref: exp_plan_cal_year.php?yearID=2001&monthID=3 )

Making a query asking for al icidences before this month was easy (day=1). For making the query after this month I used this one:

$num_days_month = cal_days_in_month(CAL_GREGORIAN, $monthID, $yearID);

THANKS a LOT, Ragnvald

  6. Re: Get month and year values   Reply   Report abuse  
Picture of Giorgos Giorgos - 2005-02-26 01:02:23 - In reply to message 5 from Ragnvald Larsen
OK, I am glad it worked.
Some other idea:
Instead of using $num_days_month = cal_days_in_month(CAL_GREGORIAN, $monthID, $yearID);
you could just use the 'private' class variable: $num_days_month = $cal->maxdays;
It contains the number of days of each calendar month [ so get just the value, DO NOT modify it :) ].