SOS: Condition if et elseif dans un formulaire de recherche
Puskas-Mozer
-
jordane45 Messages postés 38486 Date d'inscription Statut Modérateur Dernière intervention -
jordane45 Messages postés 38486 Date d'inscription Statut Modérateur Dernière intervention -
Bonjour,
Je suis entrain de développer une application dans laquelle il y a un champ de recherche affichant les données spécifique à partir de la base de données dans un tableau. Mais je veux que lorsque par exemple que l'utilisateur click sur le bouton CHERCHER sans autant saisir quelque chose dans le champs, que rien ne s'affiche dans le tableau.
C'est ce qui m'a bloqué, merci d'avance pour votre aide
<style>
.titre {
font-family: Algerian, Castellar, Cambria;
font-size: 36px;
color: #0000FF;
background-image:url()
}
</style>
<!DOCTYPE html>
<html lang="fr-FR">
<head>
<title>MENU PUBLIC</title>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
</head>
<body>
<?php
include("menustrip.php");
?>
<br>
<br><br><br><center>
<h2><strong><a href="index2.php">RETOUR</a></strong></h2>
<?php
require_once("connection.php");
$mc="Null";
if(isset($_POST['motCle'])){
$mc=$_POST['motCle'];
}
$req="select * from DEPISTAGE where COD_PREL like '%$mc%'";
$rs=mysql_query($req) or die(mysql_error());
?>
<head>
<meta charset="UTF-8">
</head>
<html>
<body>
<form method="POST" action"casLabo.php">
<b>Mot clé :</b><input type="text" name="motCle" value="<?php echo($mc)?>" placeholder="Saisir le code ici">
<input type="submit" value="Chercher">
<table border="1" width="80%">
<tr>
<th>CODE</th>
<th>NOM</th>
<th>DATE</th>
<th>TYPE</th>
<th>TYPE CAS</th>
<th>RESULTAT</th>
<th>LABORATOIRE</th>
<th>ETAT</th>
<th>TEL PERSONNE</th>
<th>NOM MEDECIN</th>
<th>TEL PRESCRIPTEUR</th>
</tr>
<?php while($ET=mysql_fetch_assoc($rs)){?>
<tr>
<td><?php echo($ET['COD_PREL'])?></td>
<td><?php echo($ET['NOM_PERS'])?></td>
<td><?php echo($ET['DATHR_PREL'])?></td>
<td><?php echo($ET['IDTYP_PREL'])?></td>
<td><?php echo($ET['IDTYP_CAS'])?></td>
<td><?php echo($ET['ID_RSLT'])?></td>
<td><?php echo($ET['ID_LABO'])?></td>
<td><?php echo($ET['COD_ETA'])?></td>
<td><?php echo($ET['TEL_PERS'])?></td>
<td><?php echo($ET['NOM_MED'])?></td>
<td><?php echo($ET['TEL_PRES'])?></td>
<td><a href="telechargerCas.php?code=<?php echo($ET['COD_PREL'])?>">Télécharger</a></td>
<td><a href="imprimerCas.php?code=<?php echo($ET['COD_PREL'])?>">Imprimer</a></td>
</tr>
<?php } ?>
</center>
<br>
<br>
</body>
Je suis entrain de développer une application dans laquelle il y a un champ de recherche affichant les données spécifique à partir de la base de données dans un tableau. Mais je veux que lorsque par exemple que l'utilisateur click sur le bouton CHERCHER sans autant saisir quelque chose dans le champs, que rien ne s'affiche dans le tableau.
C'est ce qui m'a bloqué, merci d'avance pour votre aide
<style>
.titre {
font-family: Algerian, Castellar, Cambria;
font-size: 36px;
color: #0000FF;
background-image:url()
}
</style>
<!DOCTYPE html>
<html lang="fr-FR">
<head>
<title>MENU PUBLIC</title>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
</head>
<body>
<?php
include("menustrip.php");
?>
<br>
<br><br><br><center>
<h2><strong><a href="index2.php">RETOUR</a></strong></h2>
<?php
require_once("connection.php");
$mc="Null";
if(isset($_POST['motCle'])){
$mc=$_POST['motCle'];
}
$req="select * from DEPISTAGE where COD_PREL like '%$mc%'";
$rs=mysql_query($req) or die(mysql_error());
?>
<head>
<meta charset="UTF-8">
</head>
<html>
<body>
<form method="POST" action"casLabo.php">
<b>Mot clé :</b><input type="text" name="motCle" value="<?php echo($mc)?>" placeholder="Saisir le code ici">
<input type="submit" value="Chercher">
<table border="1" width="80%">
<tr>
<th>CODE</th>
<th>NOM</th>
<th>DATE</th>
<th>TYPE</th>
<th>TYPE CAS</th>
<th>RESULTAT</th>
<th>LABORATOIRE</th>
<th>ETAT</th>
<th>TEL PERSONNE</th>
<th>NOM MEDECIN</th>
<th>TEL PRESCRIPTEUR</th>
</tr>
<?php while($ET=mysql_fetch_assoc($rs)){?>
<tr>
<td><?php echo($ET['COD_PREL'])?></td>
<td><?php echo($ET['NOM_PERS'])?></td>
<td><?php echo($ET['DATHR_PREL'])?></td>
<td><?php echo($ET['IDTYP_PREL'])?></td>
<td><?php echo($ET['IDTYP_CAS'])?></td>
<td><?php echo($ET['ID_RSLT'])?></td>
<td><?php echo($ET['ID_LABO'])?></td>
<td><?php echo($ET['COD_ETA'])?></td>
<td><?php echo($ET['TEL_PERS'])?></td>
<td><?php echo($ET['NOM_MED'])?></td>
<td><?php echo($ET['TEL_PRES'])?></td>
<td><a href="telechargerCas.php?code=<?php echo($ET['COD_PREL'])?>">Télécharger</a></td>
<td><a href="imprimerCas.php?code=<?php echo($ET['COD_PREL'])?>">Imprimer</a></td>
</tr>
<?php } ?>
</center>
<br>
<br>
</body>
1 réponse
Bonjour,
Déjà.. lorsque tu postes du code sur le forum, merci de le faire en utilisant les balises de code.
Explications ( à lire ENTIEREMENT ) disponibles ici : https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code
Ensuite, évites d'ouvrir plusieurs discussions pour le même souci.
J'ai fermé ta précédente discussion !
Et donc pour ta question
et dans ton tableau
Déjà.. lorsque tu postes du code sur le forum, merci de le faire en utilisant les balises de code.
Explications ( à lire ENTIEREMENT ) disponibles ici : https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code
Ensuite, évites d'ouvrir plusieurs discussions pour le même souci.
J'ai fermé ta précédente discussion !
Et donc pour ta question
<?php require_once("connection.php"); $mc=null; if(isset($_POST['motCle'])){ $mc=$_POST['motCle']; $req="select * from DEPISTAGE where COD_PREL like '%$mc%'"; $rs=mysql_query($req) or die(mysql_error()); } ?>
et dans ton tableau
<?php if(!empty($rs)){ while($ET=mysql_fetch_assoc($rs)){ ?> <tr> <td><?php echo($ET['COD_PREL'])?></td> <td><?php echo($ET['NOM_PERS'])?></td> <td><?php echo($ET['DATHR_PREL'])?></td> <td><?php echo($ET['IDTYP_PREL'])?></td> <td><?php echo($ET['IDTYP_CAS'])?></td> <td><?php echo($ET['ID_RSLT'])?></td> <td><?php echo($ET['ID_LABO'])?></td> <td><?php echo($ET['COD_ETA'])?></td> <td><?php echo($ET['TEL_PERS'])?></td> <td><?php echo($ET['NOM_MED'])?></td> <td><?php echo($ET['TEL_PRES'])?></td> <td><a href="telechargerCas.php?code=<?php echo($ET['COD_PREL'])?>">Télécharger</a></td> <td><a href="imprimerCas.php?code=<?php echo($ET['COD_PREL'])?>">Imprimer</a></td> </tr> <?php } } ?>