1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
<!-- Table
================================================== -->
<fieldset class="tableau">
<legend class="ttr1"><h4>Salarié recherché</h4></legend>
<?php
// 1- récupération
$matricule_search = ( !empty($_POST['matricule_search']) )? $_POST['matricule_search'] : '';
$nom_search = ( !empty($_POST['nom_search']) )? $_POST['nom_search'] : '';
$prenom_search = ( !empty($_POST['prenom_search']) )? $_POST['prenom_search'] : '';
// 2- initialisation
$where = array();
$params = array();
// 3- construction de la requête
if( !empty($matricule_search) )
{
$where[] = " (matricule_employe LIKE ?) ";
$params[] = '%'.$matricule_search.'%';
}
if( !empty($nom_search) && !empty($prenom_search) )
{
$where[] = " (nom_employe LIKE ? AND prenom_employe LIKE ?) ";
$params[] = '%'.$nom_search.'%';
$params[] = '%'.$prenom_search.'%';
}
// 4- clause WHERE
$where = ( !empty($where) )? " WHERE " . implode( " OR ", $where ) : ""; // OR : l'un OU l'autre
// 5- finalisation :
$sql = "SELECT * FROM employe_table" . $where . "";
$data=array();
$db = include 'includes/connect_bdd.php';
try {
$stmt = $db->prepare( $sql );
$stmt->execute( $params );
while($row= $stmt->fetch(PDO::FETCH_ASSOC)){
$data[]=$row;
}
unset($db);
if(count($data)>0){
$table ='<table>'."\n";
$table.='<thead>'."\n";
$table.='<tr><th>Matricule</th>
<th>Nom</th>
<th>Prenom</th>
<th>Date de naissance</th>
<th>Date d embauche</th>
<th>Photo</th>
<th>Contrat</th>
<th>Fonction</th>
<th>Statut</th>
<th>Carte d identite</th>
<th>Carte BTP</th></tr>'."\n";
$table.='</thead>'."\n";
$table.='<tbody>'."\n";
foreach($data as $donnee){
$table.='<tr><td>'.$donnee['matricule_employe'].'</td>
<td>'.$donnee['nom_employe'].'</td>
<td>'.$donnee['prenom_employe'].'</td>
<td>'.$donnee['datenaiss_employe'].'</td>
<td>'.$donnee['date_embauche_employe'].'</td>
<td>'.$donnee['photo_employe'].'</td>
<td>'.$donnee['contrat_employe'].'</td>
<td>'.$donnee['fonction_employe'].'</td>
<td>'.$donnee['statut_employe'].'</td>
<td>'.$donnee['carte_identite_employe'].'</td>
<td>'.$donnee['carte_btp_employe'].'</td></tr>'."\n";
}
$table.='</tbody>'."\n";
$table.='</table>'."\n";
echo $table;
}
else{
echo 'Aucun resultat pour cette requete';
}
} catch (Exception $e) {
echo "Erreur ! " . $e->getMessage() . "<br/>";
}
?> |