By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,521 Members | 1,460 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,521 IT Pros & Developers. It's quick & easy.

PHP Table

P: 2
Hello everybody,

am New in PHP. I would appreciate some help in the below code . What i need is a yearly calender that displays only the months without days .So i can load the data on a monthly basis.


<?php
defined( '_VALID_MOS' ) or die( 'Restricted access' );
require_once( $mainframe->getPath( 'front_html' ) );

// page title
$mainframe->setPageTitle( 'Callout' );

echo "

<center>";



//Check for a Month Change submission

if (isset($_POST['submit']))
{
$submit = $_POST['submit'];
$month_now = $_POST["month_now"];
$year_now = $_POST["year_now"];
// Subtract one from the month for previous, add one for next
//<body bgcolor='pink'>
if ($submit == "Prev")
{

if($month_now >6 && $year_now >= 2007)
$year_now--;


else if($month_now <=6 && $year_now > 2007)
$year_now--;
}
else
{


if($month_now < date("m") && $year_now <= date("Y"))
$year_now++;

else if($month_now > date("m") && $year_now < date("Y"))
$year_now++;

}

$date = getdate(mktime(0,0,0,$month_now,1,$year_now));
}
else
{
$date = getdate();
}

$month_num = $date["mon"];
$month_name = $date["month"];
$year = $date["year"];
$date_today = getdate(mktime
(0,0,0,$month_num,1,$year));
$first_week_day = $date_today["wday"];
$cont = true;
$today = 27;

while (($today <= 32) && ($cont))
{
$date_today = getdate(mktime(0,0,0,$month_num,$today,$year));

if ($date_today["mon"] != $month_num)
{
$lastday = $today - 1;
$cont = false;
}

$today++;
}

// allow for form submission to the script for forward
//and backwards

echo"<table width=\"300\" border=\"1\" cellspacing=4 cellpadding=2 style='text-align:center; font-
size:30.0pt;font-family:veranda; style=text-weight:bold; color:#666666'>
<tr align=center style='font-weight:bold'><td colspan=\"7\">$year</td>
</tr>";

// begin placement of days according to their
//beginning weekday

$day = 1;
$month = 1;
$wday = $first_week_day;
$firstweek = true;


// make each day linkable to the following filec2.php
//page

if ( intval($month_num) < 10) { $new_month_num = "0$month_num"; }
elseif (intval($month_num) >= 10)
{
$new_month_num = $month_num;
}
if ( intval($day) < 10) { $new_day = "0$day";
}
elseif (intval($day) >= 10) { $new_day = $day;
}
//$link_date = "$new_day-$new_month_num-$year";


//$today_year = date("Y");
$today_year = date("Y");
$today_month = date("F");
$today_day = date("j");
$today_month_num = date("m");

if($day == $today_day && $month_name == $today_month && $year == $today_year)
$colour = 'yellow';

else
$colour = '#FFFCC0';


$link_date = "$year$new_month_num";

if($day <= $today_day && $new_month_num <= $today_month_num && $year == $today_year)
{
if (is_file('.\res\Callout\callout'.$link_date.'.xls' ))
echo "<a href=res\Callout\callout$link_date.xls target=\"_blank\"> $month_name
</a></td>";
else
echo "$month_name ";
}
else if($day > $today_day && $new_month_num < $today_month_num && $year <= $today_year)
{
if (is_file('.\res\Callout\callout'.$link_date.'.xls' ))
echo "<a href=res\Callout\callout$link_date.xls
target=\"_blank\"> $month_name </a></td>";
else
echo "$month_name ";
}
else if($new_month_num >= $today_month_num && $year < $today_year)
{
if (is_file('.\res\Callout\callout'.$link_date.'.xls' ))
echo "<a href=res\Callout\callout$link_date.xls target=\"_blank\"> $month_name
</a>";
else
echo "$month_name ";
}



if ($month_name==12)
{
echo "</tr>\n";
}

//$wday++;
//$wday = $wday % 7;
$month_name++;
//}
echo"

</table>
<br>

";
?>
May 6 '07 #1
Share this Question
Share on Google+
2 Replies


pbmods
Expert 5K+
P: 5,821
What i need is a yearly calender that displays only the months without days .So i can load the data on a monthly basis.
http://php.net/date
http://php.net/strtotime

The fastest way to do this is to actually define the month names yourself. It's faster to look up an array index 12 times than to run strtotime 12 times.
[PHP]
$monthNames = array(
1 => 'January',
2 => 'February',
etc.
);

// isValidMonth checks to make sure $_REQUEST['month'] is set and is a number between 1 and 12.
$currentMonth = (isValidMonth($_REQUEST['month'])
? $_REQUEST['month']
: date('n')
);

// My first programming teacher would kill me for not using a variable to store the value 13 ('What if they add another month to the calendar?').
for($i = 1; $i < 13; $i++)
print((($i == $currentMonth) ? '<b>' : '') . "<a href=\"calendar.php?month=$i\">{$monthNames[$i]}</a>" . (($i == $currentMonth) ? '</b>' : '') . '<br />');
[/PHP]
May 6 '07 #2

P: 2
http://php.net/date
http://php.net/strtotime

The fastest way to do this is to actually define the month names yourself. It's faster to look up an array index 12 times than to run strtotime 12 times.
[PHP]
$monthNames = array(
1 => 'January',
2 => 'February',
etc.
);

// isValidMonth checks to make sure $_REQUEST['month'] is set and is a number between 1 and 12.
$currentMonth = (isValidMonth($_REQUEST['month'])
? $_REQUEST['month']
: date('n')
);

// My first programming teacher would kill me for not using a variable to store the value 13 ('What if they add another month to the calendar?').
for($i = 1; $i < 13; $i++)
print((($i == $currentMonth) ? '<b>' : '') . "<a href=\"calendar.php?month=$i\">{$monthNames[$i]}</a>" . (($i == $currentMonth) ? '</b>' : '') . '<br />');
[/PHP]

===============================


Thanx alot for answering my question.
But as I told u i am a very new user in PHP .So if you please tell me how to include the given commands from you to my script & where..
May 6 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.