- Home
- Categorie
- Coding e Sistemistica
- PHP
- Problema calendario php
-
Problema calendario php
Ciao, ho trovato su internet un piccolo script in php per un calendario... l'unico problema è che è quadrato... mentre io avrei bisogno che fosse rettangolare cioè non in base ai giorni dal lunedì alla domenica ma in base ai giorni di calendario avendo solo due righe una con i giorni del mese (1,2,3,4,...., 31) e una con i giorni della settimana (L,M,M,G,V,S,D)...
Ho provato a modificare i paramenti da solo ma dopo molti tentativi (alla cieca) mi sto arrendendo...
Qualcuno sa come modificarlo? Almeno per farlo uscire rettangolare invece che quadrato?
Grazie mille
Ciao[php]
<?php
// if ym is set, i.e. somebody clicked on next or previous months link
if(isset($_GET["ym"]))
{
$year = (int)substr($_GET["ym"], 0, 4);
$month = (int)substr($_GET["ym"], 4, 2);
}
else // otherwise take current month & year
{
$month = date("m", mktime(0,0,0,date('m'),1,date('Y')));
$year = date("Y", mktime(0,0,0,date('m'),1,date('Y')));
}$skip = date("w", mktime(0,0,0,$month,1,$year)); // days to skip in 1 row of week.
$daysInMonth = date("t", mktime(0,0,0,$month,1,$year)); // total number of dates in the month.
$calendar_head = ''; // for calendar head
$calendar_body = ''; // for calendar boday
$day = 1; // For date in calendarfor($i = 0; $i < 6; $i++) // Outer loop for weeks
{
$calendar_body .= '<tr>'; // start row tag
for($j = 0; $j < 7; $j++) // Inner loop for week days
{
if(($skip > 0)||($day > $daysInMonth)) // display blank till 1 day of month or after total numnber of days in that month
{
$calendar_body .= '<td> </td>';
$skip--;
}
else
{
if($j == 0) // if its Sunday then add class holiday
$calendar_body .= '<td class="holiday">'.$day.'</td>';
else // otherwise add day class
$calendar_body .= '<td class="day">'.$day.'</td>';$day++; // Increment $day } } // inner loop closes $calendar_body .= '</tr>'; // end row tag
} // outer loop closes
// Calendar head section
$calendar_head = '
<tr>
<th colspan="2"><a href="?ym='.date("Ym", mktime(0,0,0,$month-1,1,$year)).'">« Previous Month</a></th>
<th colspan="3">'.date("F, Y", mktime(0,0,0,$month,1,$year)).'</th>
<th colspan="2"><a href="?ym='.date("Ym", mktime(0,0,0,$month+1,1,$year)).'">Next Month »</a></th>
</tr>
<tr>
<th>Sunday</th>
<th>Monday</th>
<th>Tuesday</th>
<th>Wednesday</th>
<th>Thursday</th>
<th>Friday</th>
<th>Saturday</th>
</tr>';
// PHP code for calendar ends?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>A Calendar Built in PHP</title><style type="text/css">
#calendar tbody tr{ height:100px; }
td{ width:100px; }
th{background-color:#CCCC99;}
.day{ background-color:#CCFFCC; }
.holiday{ background-color:#FFCC66; }</style>
</head>
<body>
<h2>A Calendar Built in PHP</h2>
<!-- Table to display calendar -->
<table id="calendar" width="710" border="1" cellspacing="0" cellpadding="5">
<thead>
<?php echo $calendar_head; ?>
</thead>
<tbody>
<?php echo $calendar_body; ?>
</tbody>
</table>
<!-- Table to display calendar --></body>
</html>[/php]
-
Ciao,
intendevi in questa maniera?[PHP]
<?php// if ym is set, i.e. somebody clicked on next or previous months link
if(isset($_GET["ym"]))
{
$year = (int)substr($_GET["ym"], 0, 4);
$month = (int)substr($_GET["ym"], 4, 2);
}
else // otherwise take current month & year
{
$month = date("m", mktime(0,0,0,date('m'),1,date('Y')));
$year = date("Y", mktime(0,0,0,date('m'),1,date('Y')));
}$skip = date("w", mktime(0,0,0,$month,1,$year)); // days to skip in 1 row of week.
$daysInMonth = date("t", mktime(0,0,0,$month,1,$year)); // total number of dates in the month.
$calendar_head = ''; // for calendar head
$calendar_body = ''; // for calendar boday
$day = 1; // For date in calendar$calendar_body .= '<tr>';
for($i = 0; $i < 6; $i++) // Outer loop for weeks
{
//$calendar_body .= '<tr>'; // start row tag
for($j = 0; $j < 7; $j++) // Inner loop for week days
{
if(($skip > 0)||($day > $daysInMonth)) // display blank till 1 day of month or after total numnber of days in that month
{
$calendar_body .= '<td> </td>';
$skip--;
}
else
{
if($j == 0) // if its Sunday then add class holiday
$calendar_body .= '<td class="holiday">'.$day.'</td>';
else // otherwise add day class
$calendar_body .= '<td class="day">'.$day.'</td>';$day++; // Increment $day } } // inner loop closes //$calendar_body .= '</tr>'; // end row tag
} // outer loop closes
$calendar_body .= '</tr>';// Calendar head section
$calendar_head = '
<tr>
<th colspan="2"><a href="?ym='.date("Ym", mktime(0,0,0,$month-1,1,$year)).'">« Previous Month</a></th>
<th colspan="3">'.date("F, Y", mktime(0,0,0,$month,1,$year)).'</th>
<th colspan="2"><a href="?ym='.date("Ym", mktime(0,0,0,$month+1,1,$year)).'">Next Month »</a></th>
</tr>
<tr> ';
for($i = 0; $i < 6; $i++) // Outer loop for weeks
{
$calendar_head .= '
<th>Sunday</th>
<th>Monday</th>
<th>Tuesday</th>
<th>Wednesday</th>
<th>Thursday</th>
<th>Friday</th>
<th>Saturday</th>';
} // outer loop closes// PHP code for calendar ends
$calendar_head .= ' </tr>';
?>[/PHP]
-
ciao, ho provato proprio ora il tuo script ma non va... uso EasyPHP... mi esce la pagina completamente bianca... come mai ?
-
Nel post sopra non ti ho copiato la parte in html dato che rimane identica (dal tag <head> in avanti)
-
@Cyrus said:
Nel post sopra non ti ho copiato la parte in html dato che rimane identica (dal tag <head> in avanti)
si una cosa del genere solo che esciono delle tabelle in più che sono vuote... mentre i giorni del mese dovrebbero corrispondere ai giorni della settimana...
Ho provato anche io così ma si presentava tutto sballato