473,386 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

PHP Table

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
2 1995
pbmods
5,821 Expert 4TB
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
Sireen
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

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

Similar topics

4
by: Gaz | last post by:
Hi, I need to have a table nested within another table. The tables are alongside each other visually speaking, and the nested table (on the right) can vary in size. My problem is that when the...
61
by: Toby Austin | last post by:
I'm trying to replace <table>s with <div>s as much as possible. However, I can't figure out how to do the following… <table> <tr> <td valign="top" width="100%">some data that will...
3
by: Terrence Brannon | last post by:
I don't know what Postgres considers a relation and had no intention of creating one when piping my schema to it... I always DROP TABLE before CREATE TABLE, so here are the ERRORS emitted when...
4
by: maricel | last post by:
I have the following base table structure - DDL: CREATE TABLE "ADMINISTRATOR"."T1" ( "C1" INTEGER NOT NULL ) IN "TEST_TS" ; ALTER TABLE "ADMINISTRATOR"."T1" ADD PRIMARY KEY
4
by: Simone Battagliero | last post by:
I wrote a program which inserts and finds elements in an hash table. Each element of the table is a dinamic list, which holds all elements having the same hash value (calculated by an int...
117
by: phil-news-nospam | last post by:
Is there really any advantage to using DIV elements with float style properies, vs. the old method of TABLE and TR and TD? I'm finding that by using DIV, it still involves the same number of...
76
MMcCarthy
by: MMcCarthy | last post by:
Normalisation is the term used to describe how you break a file down into tables to create a database. There are 3 or 4 major steps involved known as 1NF (First Normal Form), 2NF (Second Normal...
7
by: Kamal | last post by:
Hello all, I have a very simple html table with collapsible rows and sorting capabilities. The collapsible row is hidden with css rule (display:none). When one clicks in the left of the...
5
by: wugon.net | last post by:
question: db2 LUW V8 UNION ALL with table function month() have bad query performance Env: db2 LUW V8 + FP14 Problem : We have history data from 2005/01/01 ~ 2007/05/xx in single big...
5
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.