Recherche par date / période
Code complet php
<a id="module"></a>
<hr>
<?php
$Depart_date = date('Y-m-d 00:00:01');
?>
<?php
if(isset($_POST['recherche-visite-date'])) {
if(!empty($_POST['histo_date_visite'])){
$histo_date = mysqli_real_escape_string($conn_RECH, $_POST['histo_date_visite']);
$LE = date("d-m-Y", strtotime(''.$histo_date.''));
}
$sql_Ouv = mysqli_query($conn_RECH, 'SELECT COUNT(id) as nbid FROM demo_visit
WHERE date_insert BETWEEN "'.$histo_date.' 00:00:01" AND "'.$histo_date.' 23:59:59" ');
while($nombre_Ouv = mysqli_fetch_assoc($sql_Ouv)){ $NB_id = $nombre_Ouv['nbid'];}
$sql_prov_Mob = mysqli_query($conn_RECH, 'SELECT COUNT(provmob) as nbprovmob FROM demo_visit
WHERE provmob != "" AND date_insert BETWEEN "'.$histo_date.' 00:00:01" AND "'.$histo_date.' 23:59:59" ');
while($nombre_prov_Mob = mysqli_fetch_assoc($sql_prov_Mob)){ $NB_provmob = $nombre_prov_Mob['nbprovmob'];}
$NB_ordi = $NB_id - $NB_provmob;
?>
<div style="border: 2px solid gray;border-radius: 10px;">
<div class="">
Le: <span style="color:#ff0000;"><?php echo $LE; ?></span>
<br />
Nombre d'ouvertures: <span style="color:#1172d3;"><?php echo $NB_id; ?></span>
<br />
Depuis Mobile: <span style="color:#1172d3;"><?php echo $NB_provmob; ?></span>
<br />
Depuis Ordi: <span style="color:#1172d3;"><?php echo $NB_ordi; ?></span>
<div style="overflow-x:auto;">
<table>
<tr class="tr_head">
<th style="width:33%">Heure</th>
<th style="width:34%">Ip</th>
<th style="width:33%">Média</th>
</tr>
<?php
$sql_recup_Ouv = mysqli_query($conn_RECH, 'SELECT * FROM demo_visit
WHERE date_insert BETWEEN "'.$histo_date.' 00:00:01" AND "'.$histo_date.' 23:59:59" ');
if (mysqli_num_rows($sql_recup_Ouv) == 0) {
echo '
<tr>
<td>
<br /> <br />
Aucun enregistrement sur cette période.
<br />
</td>
</tr>
';
} else {
while($recup_Ouv = mysqli_fetch_assoc($sql_recup_Ouv)){
$id = $recup_Ouv['id'];
$date_insert = $recup_Ouv['date_insert'];
$ip = $recup_Ouv['ip'];
$Prov_Media = $recup_Ouv['provmob'];
$date_heure = date("H:i", strtotime(''.$recup_Ouv['date_insert'].''));
$pair ++;
if($pair % 2 == 0){$style = 'pair';}else{$style = 'impair';}
?>
<tr class="tr_ligne">
<td style="color:#1172d3;font-size:14px;font-weight:400;">
<div class="text-center">
<span><?php echo $date_heure ?></span>
</div>
</td>
<td>
<div class="text-left columns1_3_panier" style="">
<div class="columns1_3_panier">
<div>
<span class="vert"><?php echo $ip; ?></span>
</div>
</div>
</div>
</td>
<td>
<div class="text-center">
<span><?php echo $Prov_Media ?></span>
</div>
</td>
</tr>
<?php
}
}
?>
</table>
</div>
<br /> <br />
</div>
</div>
<br /> <br />
<?php
}
?>
<?php
if(isset($_POST['recherche-visite-periode'])) {
if(!empty($_POST['depart_date_visite'])){ $depart_date = mysqli_real_escape_string($conn_RECH, $_POST['depart_date_visite']); }
if(!empty($_POST['fin_date_visite'])){ $fin_date = mysqli_real_escape_string($conn_RECH, $_POST['fin_date_visite']); }
$sql_Ouv = mysqli_query($conn_RECH, 'SELECT COUNT(id) as nbid FROM demo_visit
WHERE date_insert BETWEEN "'.$depart_date.' 00:00:01" AND "'.$fin_date.' 23:59:59" ');
while($nombre_Ouv = mysqli_fetch_assoc($sql_Ouv)){ $NB_id = $nombre_Ouv['nbid'];}
$sql_prov_Mob = mysqli_query($conn_RECH, 'SELECT COUNT(provmob) as nbprovmob FROM demo_visit
WHERE provmob != "" AND date_insert BETWEEN "'.$depart_date.' 00:00:01" AND "'.$fin_date.' 23:59:59" ');
while($nombre_prov_Mob = mysqli_fetch_assoc($sql_prov_Mob)){ $NB_provmob = $nombre_prov_Mob['nbprovmob'];}
$NB_ordi = $NB_id - $NB_provmob;
$DU = date("d-m-Y", strtotime(''.$depart_date.''));
$AU = date("d-m-Y", strtotime(''.$fin_date.''));
?>
<div style="border: 2px solid gray;border-radius: 10px;">
<div class="col-md-12">
Du: <span style="color:#ff0000;"><?php echo $DU; ?></span> Au: <span style="color:#ff0000;"><?php echo $AU; ?></span>
<br />
Nombre d'ouvertures: <span style="color:#1172d3;"><?php echo $NB_id; ?></span>
<br />
Depuis Mobile: <span style="color:#1172d3;"><?php echo $NB_provmob; ?></span>
<br />
Depuis Ordi: <span style="color:#1172d3;"><?php echo $NB_ordi; ?></span>
<div style="overflow-x:auto;">
<table>
<tr class="tr_head">
<th style="width:33%">Heure</th>
<th style="width:34%">Ip</th>
<th style="width:33%">Média</th>
</tr>
<?php
$sql_recup_Ouv = mysqli_query($conn_RECH, 'SELECT * FROM demo_visit
WHERE date_insert BETWEEN "'.$depart_date.' 00:00:01" AND "'.$fin_date.' 23:59:59" ');
if (mysqli_num_rows($sql_recup_Ouv) == 0) {
echo '
<tr>
<td>
<br /> <br />
Aucun enregistrement sur cette période.
<br />
</td>
</tr>
';
} else {
while($recup_Ouv = mysqli_fetch_assoc($sql_recup_Ouv)){
$id = $recup_Ouv['id'];
$date_insert = $recup_Ouv['date_insert'];
$ip = $recup_Ouv['ip'];
$Prov_Media = $recup_Ouv['provmob'];
$date_courte = date("d-m", strtotime(''.$recup_Ouv['date_insert'].''));
$date_heure = date("H:i", strtotime(''.$recup_Ouv['date_insert'].''));
$pair ++;
if($pair % 2 == 0){$style = 'pair';}else{$style = 'impair';}
?>
<tr class="tr_ligne">
<td style="font-size:14px;font-weight:400;">
<div class="text-center">
<span><?php echo $date_courte ?></span> - <span style="color:#1172d3;"><?php echo $date_heure ?></span>
</div>
</td>
<td>
<div class="text-left columns1_3_panier" style="">
<div class="columns1_3_panier">
<div>
<span class="vert"><?php echo $ip; ?></span>
</div>
</div>
</div>
</td>
<td>
<div class="text-center">
<span><?php echo $Prov_Media ?></span>
</div>
</td>
</tr>
<?php
}
}
?>
</table>
</div>
<br /> <br />
</div>
</div>
<br /> <br />
<?php
}
?>
<br />
<div style="width: 96%;padding-left: 10px;padding-right: 10px;border: 2px solid gray;border-radius: 10px;">
<form method = "post" action = "#module">
<br />
<input type="date" name="histo_date_visite" min="2020-09-01" max="2020-09-30" required>
<br /> <br />
<span style="float:right;"><input name = "recherche-visite-date" id = "recherche-visite-date" type="submit" class="bouton-paiement" value="Par Date" />
<br />
</span>
</form>
<hr>
<form method = "post" action = "#module">
<br />
<input type="date" name="depart_date_visite" required>
<br /> <br />
<input type="date" name="fin_date_visite" required>
<br /> <br />
<span style="float:right;"><input name = "recherche-visite-periode" id = "recherche-visite-periode" type="submit" class="bouton-paiement" value="Par Période" />
<br />
</span>
</form>
<hr>
<br /> <br />
</div>