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
| <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Recherche</title>
</head>
<body>
<?php include('pdoconfig.php');
//On se connecte
try{
$liste = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
}
catch(PDOException $e){
echo "Erreur : " . $e->getMessage();
}
?>
<!--On affiche la liste déroulante-->
<form method='post'>
<select name="recherche_valeur" id="bot-select" required>
<?php
$reponseliste = $liste->query('select nom_bots from nom_bots');
while ($donneesliste = $reponseliste->fetch())
{
?>
<option value="<?php echo $donneesliste['nom_bots']; ?>"><?php echo $donneesliste['nom_bots']; ?></option>
<?php
}
?>
</select>
<input type='submit' value="Rechercher" />
</form>
<!--On affiche le résultat de la recherche-->
<table>
<thead>
<tr>
<th>Bots</th>
</tr>
</thead>
<tbody>
<?php
$sql='select nom_bots from nom_bots';
$params=[];
if(isset($_POST['recherche_valeur'])){
$sql.=' where nom_bots like :nom_bots';
$params[':nom_bots']="%".addcslashes($_POST['recherche_valeur'],'_')."%";
}
$resultats=$liste->prepare($sql);
$resultats->execute($params);
if($resultats->rowCount()>0){
while($d=$resultats->fetch(PDO::FETCH_ASSOC)){
?>
<tr>
<td><?=$d['nom_bots']?></td>
</tr>
<?php
}
$resultats->closeCursor();
}
else echo '<tr><td colspan=4>aucun résultat trouvé</td></tr>'.
$connect=null;
?>
</tbody>
</table>
</body>
</html> |
Partager