<?php
if (isset($_POST['cerca']) && $_POST['cerca'] == 'Cerca') {
$d_day = $_POST['d_day'];
$d_month = $_POST['d_month'];
$d_year = $_POST['d_year'];
$a_day = $_POST['a_day'];
$a_month = $_POST['a_month'];
$a_year = $_POST['a_year'];
if (checkdate($d_month, $d_day, $d_year)) {
$dal = "$d_year-$d_month-$d_day";
if (checkdate($a_month, $a_day, $a_year)) {
$al = "$a_year-$a_month-$a_day";
$query = "SELECT * FROM tabella
WHERE Data BETWEEN '$dal' AND DATE_ADD('$al',INTERVAL 1 DAY)";
//qui la query andrà eseguita
echo $query;
} else {
echo "<script type='text/javascript'>
alert('La seconda data non è valida');
</script>";
}
} else {
echo "<script type='text/javascript'>
alert('La prima data non è valida');
</script>";
}
} else {
$d_day = '01';
$d_month = date('m');
$d_year = date('Y');
$a_day = date('d');
$a_month = date('m');
$a_year = date('Y');
}
$mesi = array(1, 'Gennaio', 'Febbraio', 'Marzo', 'Aprile', 'Maggio',
'Giugno', 'Luglio', 'Agosto', 'Settembre', 'Ottobre', 'Novembre', 'Dicembre');
echo "<form action='test.php' method='post'>";
echo "<div class='mioForm'>";
echo "Dal <select name='d_day'>";
for ($i = 1; $i < 32; $i++) {
$i = str_pad($i, 2, '0', STR_PAD_LEFT);
echo "<option value='$i'";
if ($d_day == $i)
echo " selected='selected'";
echo ">$i</option>\n";
}
echo "</select> ";
echo " <select name='d_month'>";
for ($x = 1; $x < 13; $x++) {
$xx = str_pad($x, 2, '0', STR_PAD_LEFT);
echo "<option value='$xx'";
if ($d_month == $xx) {
echo " selected='selected'";
}
echo ">$mesi[$x]</option>\n";
}
echo "</select> ";
echo "<select name='d_year'>";
for ($y = 2000; $y <= date('Y'); $y++) {
echo "<option value='$y'";
if ($d_year == $y)
echo " selected='selected'";
echo ">$y</option>\n";
}
echo "</select> ";
echo "Al <select name='a_day'>";
for ($i = 1; $i < 32; $i++) {
$i = str_pad($i, 2, '0', STR_PAD_LEFT);
echo "<option value='$i'";
if ($a_day == $i)
echo " selected='selected'";
echo ">$i</option>\n";
}
echo "</select> ";
echo " <select name='a_month'>";
for ($x = 1; $x < 13; $x++) {
$xx = str_pad($x, 2, '0', STR_PAD_LEFT);
echo "<option value='$xx'";
if ($a_month == $xx) {
echo " selected='selected'";
}
echo ">$mesi[$x]</option>\n";
}
echo "</select> ";
echo "<select name='a_year'>";
for ($y = 2000; $y <= date('Y'); $y++) {
echo "<option value='$y'";
if ($a_year == $y)
echo " selected='selected'";
echo ">$y</option>\n";
}
echo "</select> ";
echo "<input type='submit' value='Cerca' name='cerca'/>";
echo "</div>";
echo "</form>";
// se la query viene eseguita mostro i risultati
if ($query) {
echo "Risultati della query";
}
?>