note 48259 added to ref.calendar
| From: | DanielSempertegui:danielflash dot tk at osu1 dot php dot net | Date: | Fri, 17 Dec 2004 01:53:39 +0000 |
| Subject: | note 48259 added to ref.calendar | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-81880@lists.php.net to get a copy of this message | ||
THX wasiq911, I have improved your code into a calendar than can swap to the previous or to the next
month and year... really useful for a calendar script. Just be aware to add two images of arrows at
each side of the calendar. Enjoy.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<?php
$mes = $HTTP_GET_VARS['mes'];
$adelanto = $HTTP_GET_VARS['adelanto'];
calendario($mes, $adelanto);
function calendario($mes, $adelanto){
?>
<table border = "1">
<tr><th bgcolor = "yellow" colspan = "2"><div
align="left">
<?php
// Si adelanto = 0 entonces se presiono flecha izquierda
if($adelanto==0){
$mes = $mes+1;
}else{
//derecha si adelanto = 1
$mes = $mes-1;
}
echo "<a href='calprueba1.php?mes=".$mes." &
adelanto=0'>";
?>
<img src="imagenes/atras.jpg" width="13" height="13"
border="0">
</a>
<?php echo date("F", mktime(0, 0, 0, date("m")-$mes, date("d"),
date("Y"))), date("Y", mktime(0, 0, 0, date("m")-$mes,
date("d"), date("Y"))); ?>
</div></th>
<th bgcolor = "yellow" colspan = "3">
<?php echo date("F", mktime(0, 0, 0, date("m")-$mes+1,
date("d"), date("Y"))), date("Y", mktime(0, 0, 0,
date("m")-$mes+1, date("d"), date("Y"))); ?>
</th><th bgcolor = "yellow" colspan = "2">
<?php echo date("F", mktime(0, 0, 0, date("m")-$mes+2,
date("d"), date("Y"))), date("Y", mktime(0, 0, 0,
date("m")-$mes+2, date("d"), date("Y"))); ?>
<?php
//Flecha de la derecha
echo "<a href='calprueba1.php?mes=".$mes." & adelanto=1'>";
?><img src="imagenes/adelante.jpg" width="13"
height="13"></a></th>
</tr>
<tr>
<th>Domingo</th>
<th>Lunes</th>
<th>Martes</th>
<th>Miércoles</th>
<th>Jueves</th>
<th>Viernes</th>
<th>Sábado</th>
</tr>
<?php
// t_days es el número de dias que tiene el mes actual = cuantos dias hay
// date("j",mktime(0,0,0,$inMonth+1,0, $inYear))
$t_days = cal_days_in_month(CAL_GREGORIAN, date("n", mktime(0, 0, 0,
date("m")-$mes+1, date("d"), date("Y"))), date("Y",
mktime(0, 0, 0, date("m")-$mes+1, date("d"), date("Y"))));
// w :numero de dia de semana 0 (for Sunday) hasta 6 (for Saturday)= donde inicia el mes
$day = date("w", mktime(0, 0, 0, date("n", mktime(0, 0, 0,
date("m")-$mes+1, date("d"), date("Y"))), 1, date("Y",
mktime(0, 0, 0, date("m")-$mes+1, date("d"), date("Y")))));
echo $t_days;
echo date("m")-$mes+1;
echo date("Y", mktime(0, 0, 0, date("m")-$mes+1, date("d"),
date("Y")));
for ($i = 0; $i <= $t_days; $i++)
{
if ($day > 6) {
echo "</tr>\n<tr>\n";
$day = 0; }
//------------------------------------------------//
if ($i == date("j")) {?>
<td align = "center"><b><a href=agenda.php><?php echo $i;
$day++; echo "</a></b></td>\n"; }
else if ($i > 0) {?>
<td align = "center"><a href=agenda.php><?php echo $i; $day++; echo
"</a></td>\n"; }
else if ($day > 0) {?>
<tr><td colspan = "<?php echo $day; ?>"><?php echo
"</td>\n"; }
//-----------------------------------------------//
if ($i == $t_days && $day < 6) {?>
<td colspan = "<?php echo 7 - $day; ?>"><?php echo
"</td>\n</tr>\n"; }
}
}
?>
</table>
</body>
</html>
----
Manual Page -- http://www.php.net/manual/en/ref.calendar.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+48259
Delete -- http://master.php.net/manage/user-notes.php?action=delete+48259&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48259&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48259&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48259&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48259&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48259&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+48259&report=yes
Search -- http://master.php.net/manage/user-notes.php