Click to See Complete Forum and Search --> : cal_info() - two dimentional array


MCP
12-24-2003, 11:14 PM
I'm trying to use cal_info() to put a calendar on my web site. From what I can tell from the help page on php.net, it produces a two dimentional array that has all the information in it. What I'm having trouble figuring out is how to extract that information from that 2D array in php. Any help would be greatly appreciated.
Thanks.

pyro
12-25-2003, 06:27 PM
Got some code, and a description of the specific problem.

MCP
12-25-2003, 07:59 PM
This is as far as I've gotten in coding the calendar.

$calendar = cal_info( CAL_JULIAN ); // gets calendar info
print($calendar[months][$month-1]); // prints month name

However the print() method above is not outputting anything. It's not giving me an error, so I think I'm just not calling the information from the array propperly.

Here's the page I was looking at on php.net about cal_info().
http://us2.php.net/manual/en/function.cal-info.php

pyro
12-25-2003, 08:10 PM
Try something along these lines:

<?PHP
$calendar = cal_info(CAL_JULIAN); # gets calendar info
echo $calendar['months'][1]; # prints first month
# or
echo $calendar['months'][count($calendar['months'])]; # maybe what you were trying to do?
?>

MCP
12-26-2003, 03:22 AM
thanks for your help everyone! :D I finally got a basic calendar working on my site. I'll probably add more functions to it later. Here's the code in case anyone's interested. Feel free to use it in your own sites. ;)

// prints a calendar
$monthname = date("F"); // gets text value for month
$monthval = date("n"); // gets numberic value for month (1-12)
$year = date("Y"); // gets four digit value for year
$startson = date ("w", mktime(0,0,0,$monthval,1,$year)); // day of week month starts on
$maxdays = cal_days_in_month(CAL_GREGORIAN,$monthval,$year); // determins the max days for the month
$calfill = $maxdays%7; // detremines total value to fill calendar table
print("<h5>$monthname\n</h5>"); // prints month name
print("<table border=0 width=\"100%\">\n<tbody>\n<tr>\n"); // starts calendar table
for ( $n = 0 ; $n < $startson ; $n++ )
{
print("<td width=5 height=5>&nbsp;</td>\n"); // print blank spaces
}
for ( $n = 1 ; $n <= $maxdays ; $n++ )
{
if( $n%7 == $maxdays%$startson )
print("</tr>\n<tr>\n"); // start new row
print("<td width=5 height=5 align=\"center\" valign=\"middle\">$n</td>"); // print day
}
for ( $n = 0 ; $n < $calfill ; $n++ )
{
print("<td>&nbsp;</td>\n"); // print blank spaces
}
print("</tr>\n</tbody>\n</table>\n"); // ends calendar table


An example of it working can be seen on my site www.enlightenedcode.net. :cool: