Jump to content

Single Line Calendar with Tables


DeadpoolMarv

Recommended Posts

Hello guy,

 

I am a newbie and I was task to create a code were this needs to be returned.

 

Tue Wed Thu Fri Sat Sun Mon Tue

ASEAN Reports 1 2 3 4 5 6 7 8 9

Country

Reports

Report1

Report2

 

I know it's not that hard for you guys that is why I came to this site.

 

Thanks in advance.

Link to comment
Share on other sites

This will return a print out of that. It's up to you to tweak and add the data you want.

 

<?php

echo 'ASEAN Reports<br>';
echo '<table>';
echo '<tr>';
echo '<th>Tue</th>';
echo '<th>Wed</th>';
echo '<th>Thur</th>';
echo '<th>Fri</th>';
echo '<th>Sat</th>';
echo '<th>Sun</th>';
echo '<th>Mon</th>';
echo '</tr>';
echo '<tr>';
echo '<td>1</td>';
echo '<td>2</td>';
echo '<td>3</td>';
echo '<td>4</td>';
echo '<td>5</td>';
echo '<td>6</td>';
echo '<td>7</td>';
echo '</tr>';
echo '</table>';
echo '<br>';
echo 'Country<br>';                           
echo 'Reports<br>';                           
echo 'Report1<br>';                           
echo 'Report2<br>';

?>

 

 

Link to comment
Share on other sites

Ahh for the fun of it.  I'm sure the BIG BOY's could do better but it was fun non the less.

<?php 

if (isset($_POST['month'])){
$m=$_POST['month'];
$y=$_POST['year'];
$viewmonth = "$m-1-$y";
}else{ 
$m = date("n"); 
$y = date("Y");
$viewmonth = date("n-j-Y",strtotime("+0 months"));
}

list($thisMonth,$thisDay,$thisYear) = preg_split('/[\/\-\ \,\.]/', $viewmonth);
$daysinmonth=date("t", mktime(0,0,0,$thisMonth,$thisDay,$thisYear));

?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
	<title></title>
	<style type="text/css">
	.table{
	background-color:#ddd;
	font-family:arial;
	font-size:12px;
	}
	</style>
	</head>
<body>
<form action="" method="post">
	<select name="month" onchange="this.form.submit()">
	<?php
	$months = array(1=>"January", 2=>"February", 3=>"March", 4=>"April", 5=>"May", 6=>"June", 7=>"July", 8=>"August", 9=>"September", 10=>"October", 11=>"November", 12=>"December");

	foreach ($months as $month =>$shown_month){
		if (isset($_POST['month'])){
			$selected_month=($_POST['month']==$month ? 'selected="selected"':'');
		}else{
			$selected_month=($m==$month ? 'selected="selected"':'');
		}
	echo "<option value=\"$month\" $selected_month>$shown_month</option>";
	}
	?>
	</select>
	<select name="year" onchange="this.form.submit()">
	<?php

	foreach(range($y,1960) as $year){		
		if (isset($_POST['year'])){
			$selected_year=($_POST['year']==$year ? 'selected="selected"':'');
		}else{
			$selected_year=($y==$year ? 'selected="selected"':'');
		}
	echo "<option value=\"$year\" $selected_year>$year</option>";
	}
	?>
	</select> 
</form>
<?php
$i=1;
$ii=1;
echo"<table class=\"table\">\r";
echo "<colgroup style='background-color:#efefef'></colgroup>\r";
while ($ii<($daysinmonth+1)){
	$fd2 = date("D", mktime(0, 0, 0, $thisMonth, $ii, $thisYear));
	if ($fd2 == 'Sat' OR $fd2 == 'Sun'){ 
		echo "<colgroup style='background-color:#C6C7CB'></colgroup>\r";
	}
	else{
		echo "<colgroup style='background-color:#ffffff'></colgroup>\r";
	}
$ii=$ii+1;
}
echo "<tr style=\"font-size:.9em;\">\r<th>ASEAN Reports</th>\r";	
while ($i<($daysinmonth+1)){
$fd = date("D", mktime(0, 0, 0, $thisMonth, $i, $thisYear));
	if ($fd == 'Sat' OR $fd == 'Sun'){
		echo "<th align=\"center\" width=\"25\" style='background-color:#dcdcdc'>$fd<br />$i</th>\r";
	}
	else{
		echo "<th align=\"center\" width=\"25\">$fd<br />$i</th>\r";
	}
$i=$i+1;
}
echo "</tr>\r";

$fakerecords=array('Country','Reports','Report1','Report2');
foreach($fakerecords as $record){ 
	echo "<tr>\r<td align=\"left\">$record</td>\r"; 
	for ($d=1; $d<=$daysinmonth; $d++){
		//DB query could be here for current date and link added to this cell
		echo "<td> </td>\r";
	}
echo "</tr>\r";
}
echo "</table>\r";
?>
</body>
</html>

Link to comment
Share on other sites


<?php 
//Set calendar to current time.
$date = strtotime('now'); //see manual for accepted formats.
//This puts the day, month, and year in seperate variables
$day = date('d', $date) ;
$month = date('m', $date) ;
$year = date('Y', $date) ;
//This gets us the month name
$monthName = date('F', $date) ; 
//Here we generate the first day of the month
$first_day = mktime(0,0,0,$month, 1, $year) ;
//Here we find out what day of the week the first day of the month falls on
$day_of_week = date('w', $first_day) ;
//Array to hold the days of the week.
$days_of_week = array('Sun','Mon','Tues','Wed','Thurs','Fri','Sat');
//We then determine how many days are in the current month
$days_in_month = cal_days_in_month(0, $month, $year) ;
//Here we start building the table heads
$calendar = '<table class="calendar">';
//first table row.
$calendar .= '<tr>';
for($i = 0; $i < $days_in_month; $i++,$day_of_week++) {
$day_of_week = ($day_of_week > 6) ? 0 : $day_of_week;
$calendar .= '<td>' . $days_of_week[$day_of_week] . '</td>';
}
$calendar .= '</tr>';
//second table row.
$calendar .= '<tr>';
for($i = 1; $i < ($days_in_month + 1); $i++) {
$calendar .= '<td>' . $i . '</td>';
}
$calendar .= '</tr></table>';


//send the calendar to output.
echo '<body>' . $calendar . '</body>';
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.