Skip to content

Instantly share code, notes, and snippets.

@catwhocode
Last active June 29, 2017 09:17
Show Gist options
  • Save catwhocode/6674bcc1b72be6ee3b679956bdd971b4 to your computer and use it in GitHub Desktop.
Save catwhocode/6674bcc1b72be6ee3b679956bdd971b4 to your computer and use it in GitHub Desktop.
latihan menampilkan listbox penanggalan hanya dengan php
<?php
$tanggalSekarang = date("j");
$bulanSekarang = date("n");
$tahunSekarang = date("Y");
// gunakan ini apabila php di-compile dengan opsi --enable-calendar
$jumlahHariBulanIni = cal_days_in_month(CAL_GREGORIAN, $bulanSekarang, $tahunSekarang);
// gunakan ini apabila php di-compile tanpa opsi --enable-calendar
// $jumlahHariBulanIni = date('t', mktime(0, 0, 0, $bulanSekarang, 1, $tahunSekarang));
echo '<select name="tanggal">';
for($tanggal=1; $tanggal <= $jumlahHariBulanIni; $tanggal++)
{
if ($tanggal == $tanggalSekarang)
{
echo '<option value="' . $tanggal . '" selected="selected">' . $tanggal . '</option>';
} else {
echo '<option value="' . $tanggal . '">' . $tanggal . '</option>';
}
}
echo '</select>';
echo '<select name="bulan">';
for ($bulan=1; $bulan <= 12; $bulan++)
{
if ($bulan == $bulanSekarang)
{
echo '<option value="' . $bulan . '" selected="selected">' . $bulan . '</option>';
} else {
echo '<option value="' . $bulan . '">' . $bulan . '</option>';
}
}
echo '</select>';
echo '<select name="tahun">';
for ($tahun=2000; $tahun <= 2020; $tahun++)
{
if ($tahun == $tahunSekarang)
{
echo '<option value="' . $tahun . '" selected="selected">' . $tahun . '</option>';
} else {
echo '<option value="' . $tahun . '">' . $tahun . '</option>';
}
}
echo '</select>';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment