<?php
$DB_SERVER = "";
$DB_USERNAME = "";
$DB_PASSWORD = "";
$DB_DATABASE = "";
$DB = mysqli_connect($DB_SERVER,$DB_USERNAME,$DB_PASSWORD,$DB_DATABASE);
?>
<html>
<head>
<title>Ricerca</title>
<style>
table, td, th, tr {
border: 1px solid #000000;
}
tr, th, td {
padding-left: 7px;
padding-right: 7px;
text-align: center;
}
table {
border-top: 15px;
}
</style>
</head>
<body>
<h1>Ricerca</h1>
<form action="" method="post">
Da: <input name="data1" type="date" value="<?php if (isset($_POST['data1'])) {echo $_POST['data1'];}?>" required/>
a: <input name="data2" type="date" value="<?php if (isset($_POST['data2'])) {echo $_POST['data2'];}?>"/>
<input name="tipouscita" type="text" placeholder="Tipo uscita" value="<?php if (isset($_POST['tipouscita'])) {echo $_POST['tipouscita'];}?>"/>
<button name="form-ricerca" type="submit">Cerca</button>
</form>
<?php
if (isset($_POST['form-ricerca'])) {
$nome_tabella = "tblprenotazioneauto";
if ($_POST['data2']<1) {
$_POST['data2'] = $_POST['data1'];
}
$data1 = $_POST['data1'];
$data1 = explode("-", $data1);
$timestamp1 = mktime(0,0,0,$data1[1],$data1[2],$data1[0]);
$data2 = $_POST['data2'];
$data2 = explode("-", $data2);
$timestamp2 = mktime(23,59,59,$data2[1],$data2[2],$data2[0]);
$field = array();
$query = "DESCRIBE ".$nome_tabella;
$result = $DB->query($query);
while ($resultarray=$result->fetch_assoc()) {
$field[] = $resultarray['Field'];
}
echo "<table>";
echo "<tr>";
foreach ($field as $thisfield) {
echo "<th>".$thisfield."</th>";
}
echo "</tr>";
if ($_POST['tipouscita']!=null AND $_POST['tipouscita']!="") {
$query = "SELECT * FROM ".$nome_tabella." WHERE str_data BETWEEN ".$timestamp1." AND ".$timestamp2." AND tipouscita='".$_POST['tipouscita']."'";
}
else {
$query = "SELECT * FROM ".$nome_tabella." WHERE str_data BETWEEN ".$timestamp1." AND ".$timestamp2;
}
$result = $DB->query($query);
while ($resultarray=$result->fetch_assoc()) {
echo "<tr>";
foreach ($field as $thisfield) {
if ($thisfield=="str_data") {
echo "<td>".date("d/m/Y",intval($resultarray[$thisfield]))."</td>";
}
else {
echo "<td>".$resultarray[$thisfield]."</td>";
}
}
echo "</tr>";
}
echo "</table>";
}
$DB->close();
?>
</body>
</html>