Hi.
I would like to build a calendar in PHP (to choose the the dat, month and year from) so users can choose their day of appointment. Could anyone tell me how or please give me a link to a tutorial.
Regards.
Hi.
I would like to build a calendar in PHP (to choose the the dat, month and year from) so users can choose their day of appointment. Could anyone tell me how or please give me a link to a tutorial.
Regards.
Hey,
Here’s something to play with.
<?php
function get($var){
return filter_input(INPUT_GET, $var);
}
function get_month(){
$month = (int)get('m');
return in_array($month, range(1, 12)) ? $month : date('n') ;
}
function get_year(){
$year = (int)get('y');
return in_array($year, range(1000, 3000)) ? $year : date('Y') ;
}
function get_prev_link($month, $year){
if(1 === $month){
return array(12, $year - 1);
}
return array($month - 1, $year);
}
function get_next_link($month, $year){
if(12 === $month){
return array(1, $year + 1);
}
return array($month + 1, $year);
}
$month = get_month();
$year = get_year();
$days = cal_days_in_month(CAL_GREGORIAN, $month, $year);
printf(
'<h1>%s %d</h1>' . PHP_EOL,
date('F', mktime(0, 0, 0, $month)),
$year
);
vprintf(
'<p><a href="?m=%d&y=%d">Previous</a></p>' . PHP_EOL,
get_prev_link($month, $year)
);
vprintf(
'<p><a href="?m=%d&y=%d">Next</a></p>' . PHP_EOL,
get_next_link($month, $year)
);
echo '<ul>' . PHP_EOL;
foreach(range(1, $days) as $day){
printf(
"\ " . '<li id="%s-%d" style="float: left; padding: 5px;">%s</li>' . PHP_EOL,
date('M', mktime(0, 0, 0, $month)),
$day,
$day
);
}
echo '</ul>' . PHP_EOL;