[RESOLU] Plusieurs possibilités à l'aide d'une seule requete

Eléphanteau du PHP | 39 Messages

13 mai 2013, 08:49

Bonjour à tous,

J'ai un menu de recherche avec 6 critères (faisant référence à une BDD). J'aimerais croiser les critères autant que possible ? Comment m'y prendre ?
Traiter les cas croisés un par un serait une mauvaise solution...

Voila ce que cela donnerait si cela était fait cas par cas...
<?php   

	 
	$bd = MaBD::getInstance(); // $bd est un objet PDO
	
	$idFicheD = $_POST['idFicheD'];
	$nomEmetteur = $_POST['nomEmetteur'];
	$especeD = $_POST['especeD'];
	$dateDemandeDeclassement = $_POST['dateDemandeDeclassement'];	
	
	// s'il n'y a que le numéro de fiche rempli, on execute la requete sur le numéro de la fiche et on affiche dans un tableau
	if ((isset($_POST['idFicheD'])) and (empty($_POST['nomEmetteur'])) and (empty($_POST['especeD'])) 
	and (empty($_POST['varieteD'])) and (empty($_POST['dateDemandeDeclassement'])) and (empty($_POST['dateCloture'])))
	{

	$req = $bd->query("SELECT * from RECHERCHE_DS WHERE idFicheD = '$idFicheD';"); // exécuter la requete

	
		echo '<table>';
		echo '<tr>';
		echo '<td><b>N°Fiche</b></td>';
		echo '<td><b>Emetteur</b></td>';
		echo '<td><b>Espèce</b></td>';
		echo '<td><b>Variété</b></td>';
		echo '<td><b>Date de saisie</b></td>';
		echo '<td><b>Date de cloture</b></td>';
		echo '</tr>';
		
	while ($ligne = $req->fetch(PDO::FETCH_ASSOC)) 
	{	
		$idFicheD = $ligne['idFicheD'];
		$dateCloture = $ligne['dateCloture'];
		echo '<tr>';
		echo '<td>'.$ligne['idFicheD'].'</td>'
		.'<td>'.$ligne['nomEmetteur'].'</td>'
		.'<td>'.$ligne['especeD'].'</td>'
		.'<td>'.$ligne['varieteD'].'</td>'
		.'<td>'.$ligne['dateDemandeDeclassement'].'</td>' 
		.'<td>'.$ligne['dateCloture'].'</td>' 
		."<td><form method='post' action='boutonModifierDS.php'>
				<input type='submit' value='Modifier' name='modifier'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>"
		."<td><form method='post' action='visualiserDS.php'>
				<input type='submit' value='Visualiser' name='visualiser'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>";
		if (($ligne['dateCloture'])== '0000-00-00')
		{
			echo "<td><form method='post' action='cloturerDS.php'>
				<input type='submit' value='Cloturer' name='cloturer'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>";
		}
		echo '</br>';
		echo '</tr>';
		
	} 
	echo '</table>';	
	echo '<br>'; // saut de ligne
	echo '<br>';
	}
	
	if ((empty($_POST['idFicheD'])) and (isset($_POST['nomEmetteur'])) and (empty($_POST['especeD'])) 
	and (empty($_POST['varieteD'])) and (empty($_POST['dateDemandeDeclassement'])) and (empty($_POST['dateCloture'])))
	{

	$req = $bd->query("SELECT * from RECHERCHE_DS WHERE nomEmetteur = '$nomEmetteur';"); // exécuter la requete

	
		echo '<table>';
		echo '<tr>';
		echo '<td><b>N°Fiche</b></td>';
		echo '<td><b>Emetteur</b></td>';
		echo '<td><b>Espèce</b></td>';
		echo '<td><b>Variété</b></td>';
		echo '<td><b>Date de saisie</b></td>';
		echo '<td><b>Date de cloture</b></td>';
		echo '</tr>';
		
	while ($ligne = $req->fetch(PDO::FETCH_ASSOC)) 
	{	
		$idFicheD = $ligne['idFicheD'];
		$dateCloture = $ligne['dateCloture'];
		echo '<tr>';
		echo '<td>'.$ligne['idFicheD'].'</td>'
		.'<td>'.$ligne['nomEmetteur'].'</td>'
		.'<td>'.$ligne['especeD'].'</td>'
		.'<td>'.$ligne['varieteD'].'</td>'
		.'<td>'.$ligne['dateDemandeDeclassement'].'</td>' 
		.'<td>'.$ligne['dateCloture'].'</td>' 
		."<td><form method='post' action='boutonModifierDS.php'>
				<input type='submit' value='Modifier' name='modifier'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>"
		."<td><form method='post' action='visualiserDS.php'>
				<input type='submit' value='Visualiser' name='visualiser'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>";
		if (($ligne['dateCloture'])== '0000-00-00')
		{
			echo "<td><form method='post' action='cloturerDS.php'>
				<input type='submit' value='Cloturer' name='cloturer'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>";
		}
		echo '</br>';
		echo '</tr>';
		
	} 
	echo '</table>';	
	echo '<br>'; // saut de ligne
	echo '<br>';
	}
	
	if ((empty($_POST['idFicheD'])) and (empty($_POST['nomEmetteur'])) and (isset($_POST['especeD'])) 
	and (empty($_POST['varieteD'])) and (empty($_POST['dateDemandeDeclassement'])) and (empty($_POST['dateCloture'])))
	{

	$req = $bd->query("SELECT * from RECHERCHE_DS WHERE especeD = '$especeD';"); // exécuter la requete

	
		echo '<table>';
		echo '<tr>';
		echo '<td><b>N°Fiche</b></td>';
		echo '<td><b>Emetteur</b></td>';
		echo '<td><b>Espèce</b></td>';
		echo '<td><b>Variété</b></td>';
		echo '<td><b>Date de saisie</b></td>';
		echo '<td><b>Date de cloture</b></td>';
		echo '</tr>';
		
	while ($ligne = $req->fetch(PDO::FETCH_ASSOC)) 
	{	
		$idFicheD = $ligne['idFicheD'];
		$dateCloture = $ligne['dateCloture'];
		echo '<tr>';
		echo '<td>'.$ligne['idFicheD'].'</td>'
		.'<td>'.$ligne['nomEmetteur'].'</td>'
		.'<td>'.$ligne['especeD'].'</td>'
		.'<td>'.$ligne['varieteD'].'</td>'
		.'<td>'.$ligne['dateDemandeDeclassement'].'</td>' 
		.'<td>'.$ligne['dateCloture'].'</td>' 
		."<td><form method='post' action='boutonModifierDS.php'>
				<input type='submit' value='Modifier' name='modifier'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>"
		."<td><form method='post' action='visualiserDS.php'>
				<input type='submit' value='Visualiser' name='visualiser'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>";
		if (($ligne['dateCloture'])== '0000-00-00')
		{
			echo "<td><form method='post' action='cloturerDS.php'>
				<input type='submit' value='Cloturer' name='cloturer'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>";
		}
		echo '</br>';
		echo '</tr>';
		
	} 
	echo '</table>';	
	echo '<br>'; // saut de ligne
	echo '<br>';
	}
	
	if ((empty($_POST['idFicheD'])) and (empty($_POST['nomEmetteur'])) and (empty($_POST['especeD'])) 
	and (isset($_POST['varieteD'])) and (empty($_POST['dateDemandeDeclassement'])) and (empty($_POST['dateCloture'])))
	{

	$req = $bd->query("SELECT * from RECHERCHE_DS WHERE varieteD = '$varieteD';"); // exécuter la requete

	
		echo '<table>';
		echo '<tr>';
		echo '<td><b>N°Fiche</b></td>';
		echo '<td><b>Emetteur</b></td>';
		echo '<td><b>Espèce</b></td>';
		echo '<td><b>Variété</b></td>';
		echo '<td><b>Date de saisie</b></td>';
		echo '<td><b>Date de cloture</b></td>';
		echo '</tr>';
		
	while ($ligne = $req->fetch(PDO::FETCH_ASSOC)) 
	{	
		$idFicheD = $ligne['idFicheD'];
		$dateCloture = $ligne['dateCloture'];
		echo '<tr>';
		echo '<td>'.$ligne['idFicheD'].'</td>'
		.'<td>'.$ligne['nomEmetteur'].'</td>'
		.'<td>'.$ligne['especeD'].'</td>'
		.'<td>'.$ligne['varieteD'].'</td>'
		.'<td>'.$ligne['dateDemandeDeclassement'].'</td>' 
		.'<td>'.$ligne['dateCloture'].'</td>' 
		."<td><form method='post' action='boutonModifierDS.php'>
				<input type='submit' value='Modifier' name='modifier'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>"
		."<td><form method='post' action='visualiserDS.php'>
				<input type='submit' value='Visualiser' name='visualiser'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>";
		if (($ligne['dateCloture'])== '0000-00-00')
		{
			echo "<td><form method='post' action='cloturerDS.php'>
				<input type='submit' value='Cloturer' name='cloturer'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>";
		}
		echo '</br>';
		echo '</tr>';
		
	} 
	echo '</table>';	
	echo '<br>'; // saut de ligne
	echo '<br>';
	}
	
		if ((empty($_POST['idFicheD'])) and (empty($_POST['nomEmetteur'])) and (empty($_POST['especeD'])) 
		and (empty($_POST['varieteD'])) and (isset($_POST['dateDemandeDeclassement'])) and (empty($_POST['dateCloture'])))
	{

	$req = $bd->query("SELECT * from RECHERCHE_DS WHERE dateDemandeDeclassement >= '$dateDemandeDeclassement';"); // exécuter la requete

	
		echo '<table>';
		echo '<tr>';
		echo '<td><b>N°Fiche</b></td>';
		echo '<td><b>Emetteur</b></td>';
		echo '<td><b>Espèce</b></td>';
		echo '<td><b>Variété</b></td>';
		echo '<td><b>Date de saisie</b></td>';
		echo '<td><b>Date de cloture</b></td>';
		echo '</tr>';
		
	while ($ligne = $req->fetch(PDO::FETCH_ASSOC)) 
	{	
		$idFicheD = $ligne['idFicheD'];
		$dateCloture = $ligne['dateCloture'];
		echo '<tr>';
		echo '<td>'.$ligne['idFicheD'].'</td>'
		.'<td>'.$ligne['nomEmetteur'].'</td>'
		.'<td>'.$ligne['especeD'].'</td>'
		.'<td>'.$ligne['varieteD'].'</td>'
		.'<td>'.$ligne['dateDemandeDeclassement'].'</td>' 
		.'<td>'.$ligne['dateCloture'].'</td>' 
		."<td><form method='post' action='boutonModifierDS.php'>
				<input type='submit' value='Modifier' name='modifier'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>"
		."<td><form method='post' action='visualiserDS.php'>
				<input type='submit' value='Visualiser' name='visualiser'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>";
		if (($ligne['dateCloture'])== '0000-00-00')
		{
			echo "<td><form method='post' action='cloturerDS.php'>
				<input type='submit' value='Cloturer' name='cloturer'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>";
		}
		echo '</br>';
		echo '</tr>';
		
	} 
	echo '</table>';	
	echo '<br>'; // saut de ligne
	echo '<br>';
	}
	
		if ((empty($_POST['idFicheD'])) and (empty($_POST['nomEmetteur'])) and (empty($_POST['especeD'])) 
		and (empty($_POST['varieteD'])) and (empty($_POST['dateDemandeDeclassement'])) and (isset($_POST['dateCloture'])))
	{

	$req = $bd->query("SELECT * from RECHERCHE_DS WHERE dateCloture >= '$dateCloture';"); // exécuter la requete

	
		echo '<table>';
		echo '<tr>';
		echo '<td><b>N°Fiche</b></td>';
		echo '<td><b>Emetteur</b></td>';
		echo '<td><b>Espèce</b></td>';
		echo '<td><b>Variété</b></td>';
		echo '<td><b>Date de saisie</b></td>';
		echo '<td><b>Date de cloture</b></td>';
		echo '</tr>';
		
	while ($ligne = $req->fetch(PDO::FETCH_ASSOC)) 
	{	
		$idFicheD = $ligne['idFicheD'];
		$dateCloture = $ligne['dateCloture'];
		echo '<tr>';
		echo '<td>'.$ligne['idFicheD'].'</td>'
		.'<td>'.$ligne['nomEmetteur'].'</td>'
		.'<td>'.$ligne['especeD'].'</td>'
		.'<td>'.$ligne['varieteD'].'</td>'
		.'<td>'.$ligne['dateDemandeDeclassement'].'</td>' 
		.'<td>'.$ligne['dateCloture'].'</td>' 
		."<td><form method='post' action='boutonModifierDS.php'>
				<input type='submit' value='Modifier' name='modifier'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>"
		."<td><form method='post' action='visualiserDS.php'>
				<input type='submit' value='Visualiser' name='visualiser'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>";
		if (($ligne['dateCloture'])== '0000-00-00')
		{
			echo "<td><form method='post' action='cloturerDS.php'>
				<input type='submit' value='Cloturer' name='cloturer'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>";
		}
		echo '</br>';
		echo '</tr>';
		
	} 
	echo '</table>';	
	echo '<br>'; // saut de ligne
	echo '<br>';
	}
	
	// aprés les 4 criteres séparés voila le croisé
	
		if ((empty($_POST['idFicheD'])) and (!empty($_POST['nomEmetteur'])) and (empty($_POST['especeD'])) 
		and (empty($_POST['varieteD'])) and (!empty($_POST['dateDemandeDeclassement'])) and (empty($_POST['dateCloture'])))
	{

	$req = $bd->query("SELECT * from RECHERCHE_DS WHERE (nomEmetteur = '$nomEmetteur' AND dateDemandeDeclassement >= '$dateDemandeDeclassement');"); // exécuter la requete

	
		echo '<table>';
		echo '<tr>';
		echo '<td><b>N°Fiche</b></td>';
		echo '<td><b>Emetteur</b></td>';
		echo '<td><b>Espèce</b></td>';
		echo '<td><b>Variété</b></td>';
		echo '<td><b>Date de saisie</b></td>';
		echo '<td><b>Date de cloture</b></td>';
		echo '</tr>';
		
	while ($ligne = $req->fetch(PDO::FETCH_ASSOC)) 
	{	
		$idFicheD = $ligne['idFicheD'];
		$dateCloture = $ligne['dateCloture'];
		echo '<tr>';
		echo '<td>'.$ligne['idFicheD'].'</td>'
		.'<td>'.$ligne['nomEmetteur'].'</td>'
		.'<td>'.$ligne['especeD'].'</td>'
		.'<td>'.$ligne['varieteD'].'</td>'
		.'<td>'.$ligne['dateDemandeDeclassement'].'</td>' 
		.'<td>'.$ligne['dateCloture'].'</td>' 
		."<td><form method='post' action='boutonModifierDS.php'>
				<input type='submit' value='Modifier' name='modifier'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>"
		."<td><form method='post' action='visualiserDS.php'>
				<input type='submit' value='Visualiser' name='visualiser'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>";
		if (($ligne['dateCloture'])== '0000-00-00')
		{
			echo "<td><form method='post' action='cloturerDS.php'>
				<input type='submit' value='Cloturer' name='cloturer'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>";
		}
		echo '</br>';
		echo '</tr>';
		
	} 
	echo '</table>';	
	echo '<br>'; // saut de ligne
	echo '<br>';
	}
	
	
		if ((empty($_POST['idFicheD'])) and (empty($_POST['nomEmetteur'])) and (!empty($_POST['especeD'])) 
		and (!empty($_POST['varieteD'])) and (empty($_POST['dateDemandeDeclassement'])) and (empty($_POST['dateCloture'])))
	{

	$req = $bd->query("SELECT * from RECHERCHE_DS WHERE (especeD = '$especeD' AND varieteD = '$varieteD');"); // exécuter la requete

	
		echo '<table>';
		echo '<tr>';
		echo '<td><b>N°Fiche</b></td>';
		echo '<td><b>Emetteur</b></td>';
		echo '<td><b>Espèce</b></td>';
		echo '<td><b>Variété</b></td>';
		echo '<td><b>Date de saisie</b></td>';
		echo '<td><b>Date de cloture</b></td>';
		echo '</tr>';
		
	while ($ligne = $req->fetch(PDO::FETCH_ASSOC)) 
	{	
		$idFicheD = $ligne['idFicheD'];
		$dateCloture = $ligne['dateCloture'];
		echo '<tr>';
		echo '<td>'.$ligne['idFicheD'].'</td>'
		.'<td>'.$ligne['nomEmetteur'].'</td>'
		.'<td>'.$ligne['especeD'].'</td>'
		.'<td>'.$ligne['varieteD'].'</td>'
		.'<td>'.$ligne['dateDemandeDeclassement'].'</td>' 
		.'<td>'.$ligne['dateCloture'].'</td>' 
		."<td><form method='post' action='boutonModifierDS.php'>
				<input type='submit' value='Modifier' name='modifier'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>"
		."<td><form method='post' action='visualiserDS.php'>
				<input type='submit' value='Visualiser' name='visualiser'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>";
		if (($ligne['dateCloture'])== '0000-00-00')
		{
			echo "<td><form method='post' action='cloturerDS.php'>
				<input type='submit' value='Cloturer' name='cloturer'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>";
		}
		echo '</br>';
		echo '</tr>';
		
	} 
	echo '</table>';	
	echo '<br>'; // saut de ligne
	echo '<br>';
	}
	
	
	if ((empty($_POST['idFicheD'])) and (!empty($_POST['nomEmetteur'])) and (!empty($_POST['especeD'])) 
		and (empty($_POST['varieteD'])) and (empty($_POST['dateDemandeDeclassement'])) and (empty($_POST['dateCloture'])))
	{

	$req = $bd->query("SELECT * from RECHERCHE_DS WHERE (especeD = '$especeD' AND nomEmetteur = '$nomEmetteur');"); // exécuter la requete

	
		echo '<table>';
		echo '<tr>';
		echo '<td><b>N°Fiche</b></td>';
		echo '<td><b>Emetteur</b></td>';
		echo '<td><b>Espèce</b></td>';
		echo '<td><b>Variété</b></td>';
		echo '<td><b>Date de saisie</b></td>';
		echo '<td><b>Date de cloture</b></td>';
		echo '</tr>';
		
	while ($ligne = $req->fetch(PDO::FETCH_ASSOC)) 
	{	
		$idFicheD = $ligne['idFicheD'];
		$dateCloture = $ligne['dateCloture'];
		echo '<tr>';
		echo '<td>'.$ligne['idFicheD'].'</td>'
		.'<td>'.$ligne['nomEmetteur'].'</td>'
		.'<td>'.$ligne['especeD'].'</td>'
		.'<td>'.$ligne['varieteD'].'</td>'
		.'<td>'.$ligne['dateDemandeDeclassement'].'</td>' 
		.'<td>'.$ligne['dateCloture'].'</td>' 
		."<td><form method='post' action='boutonModifierDS.php'>
				<input type='submit' value='Modifier' name='modifier'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>"
		."<td><form method='post' action='visualiserDS.php'>
				<input type='submit' value='Visualiser' name='visualiser'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>";
		if (($ligne['dateCloture'])== '0000-00-00')
		{
			echo "<td><form method='post' action='cloturerDS.php'>
				<input type='submit' value='Cloturer' name='cloturer'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>";
		}
		echo '</br>';
		echo '</tr>';
		
	} 
	echo '</table>';	
	echo '<br>'; // saut de ligne
	echo '<br>';
	}
	
	if ((empty($_POST['idFicheD'])) and (empty($_POST['nomEmetteur'])) and (empty($_POST['especeD'])) 
		and (empty($_POST['varieteD'])) and (!empty($_POST['dateDemandeDeclassement'])) and (!empty($_POST['dateCloture'])))
	{

	$req = $bd->query("SELECT * from RECHERCHE_DS WHERE (dateDemandeDeclassement >= '$dateDemandeDeclassement' AND dateCloture >= '$dateCloture');"); // exécuter la requete

	
		echo '<table>';
		echo '<tr>';
		echo '<td><b>N°Fiche</b></td>';
		echo '<td><b>Emetteur</b></td>';
		echo '<td><b>Espèce</b></td>';
		echo '<td><b>Variété</b></td>';
		echo '<td><b>Date de saisie</b></td>';
		echo '<td><b>Date de cloture</b></td>';
		echo '</tr>';
		
	while ($ligne = $req->fetch(PDO::FETCH_ASSOC)) 
	{	
		$idFicheD = $ligne['idFicheD'];
		$dateCloture = $ligne['dateCloture'];
		echo '<tr>';
		echo '<td>'.$ligne['idFicheD'].'</td>'
		.'<td>'.$ligne['nomEmetteur'].'</td>'
		.'<td>'.$ligne['especeD'].'</td>'
		.'<td>'.$ligne['varieteD'].'</td>'
		.'<td>'.$ligne['dateDemandeDeclassement'].'</td>' 
		.'<td>'.$ligne['dateCloture'].'</td>' 
		."<td><form method='post' action='boutonModifierDS.php'>
				<input type='submit' value='Modifier' name='modifier'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>"
		."<td><form method='post' action='visualiserDS.php'>
				<input type='submit' value='Visualiser' name='visualiser'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>";
		if (($ligne['dateCloture'])== '0000-00-00')
		{
			echo "<td><form method='post' action='cloturerDS.php'>
				<input type='submit' value='Cloturer' name='cloturer'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>";
		}
		echo '</br>';
		echo '</tr>';
		
	} 
	echo '</table>';	
	echo '<br>'; // saut de ligne
	echo '<br>';
	}
	
	if ((empty($_POST['idFicheD'])) and (!empty($_POST['nomEmetteur'])) and (empty($_POST['especeD'])) 
		and (!empty($_POST['varieteD'])) and (empty($_POST['dateDemandeDeclassement'])) and (empty($_POST['dateCloture'])))
	{

	$req = $bd->query("SELECT * from RECHERCHE_DS WHERE (nomEmetteur = '$nomEmetteur' AND varieteD = '$varieteD');"); // exécuter la requete

	
		echo '<table>';
		echo '<tr>';
		echo '<td><b>N°Fiche</b></td>';
		echo '<td><b>Emetteur</b></td>';
		echo '<td><b>Espèce</b></td>';
		echo '<td><b>Variété</b></td>';
		echo '<td><b>Date de saisie</b></td>';
		echo '<td><b>Date de cloture</b></td>';
		echo '</tr>';
		
	while ($ligne = $req->fetch(PDO::FETCH_ASSOC)) 
	{	
		$idFicheD = $ligne['idFicheD'];
		$dateCloture = $ligne['dateCloture'];
		echo '<tr>';
		echo '<td>'.$ligne['idFicheD'].'</td>'
		.'<td>'.$ligne['nomEmetteur'].'</td>'
		.'<td>'.$ligne['especeD'].'</td>'
		.'<td>'.$ligne['varieteD'].'</td>'
		.'<td>'.$ligne['dateDemandeDeclassement'].'</td>' 
		.'<td>'.$ligne['dateCloture'].'</td>' 
		."<td><form method='post' action='boutonModifierDS.php'>
				<input type='submit' value='Modifier' name='modifier'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>"
		."<td><form method='post' action='visualiserDS.php'>
				<input type='submit' value='Visualiser' name='visualiser'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>";
		if (($ligne['dateCloture'])== '0000-00-00')
		{
			echo "<td><form method='post' action='cloturerDS.php'>
				<input type='submit' value='Cloturer' name='cloturer'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>";
		}
		echo '</br>';
		echo '</tr>';
		
	} 
	echo '</table>';	
	echo '<br>'; // saut de ligne
	echo '<br>';
	}
	
	if ((!empty($_POST['idFicheD'])) and (!empty($_POST['nomEmetteur'])) and (!empty($_POST['especeD'])) 
		and (!empty($_POST['varieteD'])) and (!empty($_POST['dateDemandeDeclassement'])) and (!empty($_POST['dateCloture'])))
	{

	$req = $bd->query("SELECT * from RECHERCHE_DS WHERE idFicheD = '$idFicheD';"); // exécuter la requete

	
		echo '<table>';
		echo '<tr>';
		echo '<td><b>N°Fiche</b></td>';
		echo '<td><b>Emetteur</b></td>';
		echo '<td><b>Espèce</b></td>';
		echo '<td><b>Variété</b></td>';
		echo '<td><b>Date de saisie</b></td>';
		echo '<td><b>Date de cloture</b></td>';
		echo '</tr>';
		
	while ($ligne = $req->fetch(PDO::FETCH_ASSOC)) 
	{	
		$idFicheD = $ligne['idFicheD'];
		$dateCloture = $ligne['dateCloture'];
		echo '<tr>';
		echo '<td>'.$ligne['idFicheD'].'</td>'
		.'<td>'.$ligne['nomEmetteur'].'</td>'
		.'<td>'.$ligne['especeD'].'</td>'
		.'<td>'.$ligne['varieteD'].'</td>'
		.'<td>'.$ligne['dateDemandeDeclassement'].'</td>' 
		.'<td>'.$ligne['dateCloture'].'</td>' 
		."<td><form method='post' action='boutonModifierDS.php'>
				<input type='submit' value='Modifier' name='modifier'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>"
		."<td><form method='post' action='visualiserDS.php'>
				<input type='submit' value='Visualiser' name='visualiser'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>";
		if (($ligne['dateCloture'])== '0000-00-00')
		{
			echo "<td><form method='post' action='cloturerDS.php'>
				<input type='submit' value='Cloturer' name='cloturer'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>";
		}
		echo '</br>';
		echo '</tr>';
		
	} 
	echo '</table>';	
	echo '<br>'; // saut de ligne
	echo '<br>';
	}
	
	
	if ((!empty($_POST['idFicheD'])) and (!empty($_POST['nomEmetteur'])) and (!empty($_POST['especeD'])) 
		and (empty($_POST['varieteD'])) and (empty($_POST['dateDemandeDeclassement'])) and (empty($_POST['dateCloture'])))
	{

	$req = $bd->query("SELECT * from RECHERCHE_DS WHERE idFicheD = '$idFicheD';"); // exécuter la requete

	
		echo '<table>';
		echo '<tr>';
		echo '<td><b>N°Fiche</b></td>';
		echo '<td><b>Emetteur</b></td>';
		echo '<td><b>Espèce</b></td>';
		echo '<td><b>Variété</b></td>';
		echo '<td><b>Date de saisie</b></td>';
		echo '<td><b>Date de cloture</b></td>';
		echo '</tr>';
		
	while ($ligne = $req->fetch(PDO::FETCH_ASSOC)) 
	{	
		$idFicheD = $ligne['idFicheD'];
		$dateCloture = $ligne['dateCloture'];
		echo '<tr>';
		echo '<td>'.$ligne['idFicheD'].'</td>'
		.'<td>'.$ligne['nomEmetteur'].'</td>'
		.'<td>'.$ligne['especeD'].'</td>'
		.'<td>'.$ligne['varieteD'].'</td>'
		.'<td>'.$ligne['dateDemandeDeclassement'].'</td>' 
		.'<td>'.$ligne['dateCloture'].'</td>' 
		."<td><form method='post' action='boutonModifierDS.php'>
				<input type='submit' value='Modifier' name='modifier'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>"
		."<td><form method='post' action='visualiserDS.php'>
				<input type='submit' value='Visualiser' name='visualiser'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>";
		if (($ligne['dateCloture'])== '0000-00-00')
		{
			echo "<td><form method='post' action='cloturerDS.php'>
				<input type='submit' value='Cloturer' name='cloturer'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>";
		}
		echo '</br>';
		echo '</tr>';
		
	} 
	echo '</table>';	
	echo '<br>'; // saut de ligne
	echo '<br>';
	}
	
	if ((!empty($_POST['idFicheD'])) and (!empty($_POST['nomEmetteur'])) and (empty($_POST['especeD'])) 
		and (empty($_POST['varieteD'])) and (empty($_POST['dateDemandeDeclassement'])) and (empty($_POST['dateCloture'])))
	{

	$req = $bd->query("SELECT * from RECHERCHE_DS WHERE idFicheD = '$idFicheD';"); // exécuter la requete

	
		echo '<table>';
		echo '<tr>';
		echo '<td><b>N°Fiche</b></td>';
		echo '<td><b>Emetteur</b></td>';
		echo '<td><b>Espèce</b></td>';
		echo '<td><b>Variété</b></td>';
		echo '<td><b>Date de saisie</b></td>';
		echo '<td><b>Date de cloture</b></td>';
		echo '</tr>';
		
	while ($ligne = $req->fetch(PDO::FETCH_ASSOC)) 
	{	
		$idFicheD = $ligne['idFicheD'];
		$dateCloture = $ligne['dateCloture'];
		echo '<tr>';
		echo '<td>'.$ligne['idFicheD'].'</td>'
		.'<td>'.$ligne['nomEmetteur'].'</td>'
		.'<td>'.$ligne['especeD'].'</td>'
		.'<td>'.$ligne['varieteD'].'</td>'
		.'<td>'.$ligne['dateDemandeDeclassement'].'</td>' 
		.'<td>'.$ligne['dateCloture'].'</td>' 
		."<td><form method='post' action='boutonModifierDS.php'>
				<input type='submit' value='Modifier' name='modifier'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>"
		."<td><form method='post' action='visualiserDS.php'>
				<input type='submit' value='Visualiser' name='visualiser'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>";
		if (($ligne['dateCloture'])== '0000-00-00')
		{
			echo "<td><form method='post' action='cloturerDS.php'>
				<input type='submit' value='Cloturer' name='cloturer'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>";
		}
		echo '</br>';
		echo '</tr>';
		
	} 
	echo '</table>';	
	echo '<br>'; // saut de ligne
	echo '<br>';
	}
	
	if ((empty($_POST['idFicheD'])) and (!empty($_POST['nomEmetteur'])) and (!empty($_POST['especeD'])) 
		and (!empty($_POST['varieteD'])) and (empty($_POST['dateDemandeDeclassement'])) and (empty($_POST['dateCloture'])))
	{

	$req = $bd->query("SELECT * from RECHERCHE_DS WHERE (nomEmetteur = '$nomEmetteur' AND especeD = '$especeD');"); // exécuter la requete

	
		echo '<table>';
		echo '<tr>';
		echo '<td><b>N°Fiche</b></td>';
		echo '<td><b>Emetteur</b></td>';
		echo '<td><b>Espèce</b></td>';
		echo '<td><b>Variété</b></td>';
		echo '<td><b>Date de saisie</b></td>';
		echo '<td><b>Date de cloture</b></td>';
		echo '</tr>';
		
	while ($ligne = $req->fetch(PDO::FETCH_ASSOC)) 
	{	
		$idFicheD = $ligne['idFicheD'];
		$dateCloture = $ligne['dateCloture'];
		echo '<tr>';
		echo '<td>'.$ligne['idFicheD'].'</td>'
		.'<td>'.$ligne['nomEmetteur'].'</td>'
		.'<td>'.$ligne['especeD'].'</td>'
		.'<td>'.$ligne['varieteD'].'</td>'
		.'<td>'.$ligne['dateDemandeDeclassement'].'</td>' 
		.'<td>'.$ligne['dateCloture'].'</td>' 
		."<td><form method='post' action='boutonModifierDS.php'>
				<input type='submit' value='Modifier' name='modifier'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>"
		."<td><form method='post' action='visualiserDS.php'>
				<input type='submit' value='Visualiser' name='visualiser'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>";
		if (($ligne['dateCloture'])== '0000-00-00')
		{
			echo "<td><form method='post' action='cloturerDS.php'>
				<input type='submit' value='Cloturer' name='cloturer'/>
				<input type='hidden' value='$idFicheD' name='idFicheD'/>
				<input type='hidden' value='$dateCloture' name='dateCloture'/>
				</form>
		</td>";
		}
		echo '</br>';
		echo '</tr>';
		
	} 
	echo '</table>';	
	echo '<br>'; // saut de ligne
	echo '<br>';
	}
	
	if ((empty($_POST['idFicheD'])) and (empty($_POST['nomEmetteur'])) and (empty($_POST['especeD'])) 
		and (empty($_POST['varieteD'])) and (empty($_POST['dateDemandeDeclassement'])) and (empty($_POST['dateCloture'])))
	{	
		echo "<p><center><u>Veuillez saisir au moins un critère !</u></center></p>";
	}
?> 
Si quelqu'un avait la solution... Ça me faciliterait la tache car cas par cas avec 6 critères ça en fait beaucoup...

ViPHP
ViPHP | 2577 Messages

13 mai 2013, 14:36

Bonjour,

il est possible de stocker la condition correspondant à chaque critère dans un array lorsque celui-ci s'applique.

if (!empty($critere1) {
  $cond[] = "critere1 = '$critere1'";
}
Puis utiliser implode() avec 'AND' pour générer la condition et créer la requête (si $cond alimenter au moins une fois)

Mammouth du PHP | 619 Messages

13 mai 2013, 14:43

Bonjour,

vous pouvez le faire de cette manier aussi
<?php

if (!empty($_POST['nomClient']) or !empty($_POST['idFiche']) or !empty($_POST['dateReclamation']) and !empty($_POST['nomRapporteur'])){
        $where="where ";        
}
else{
        $where="";      
}



if(isset($_POST['nomRapporteur']) and !empty($_POST['nomRapporteur'])){$where.="nomRapporteur = '".$_POST['nomRapporteur']."' and ";}
if(isset($_POST['nomClient']) and !empty($_POST['nomClient'])){$where.="nomClient = '".$_POST['nomClient']."' and ";}
if(isset($_POST['idFiche']) and !empty($_POST['idFiche'])){$where.="idFiche = '".$_POST['idFiche']."' and ";}
if(isset($_POST['dateReclamation']) and !empty($_POST['dateReclamation'])){$where.="dateReclamation >='".$_POST['dateReclamation']."' and ";}


if(!empty($where)){$where = substr($where, 0, -4);}

$req = $bd->query("SELECT * from RECHERCHE_RC1 $where");


?>

Eléphanteau du PHP | 39 Messages

13 mai 2013, 15:09

Merci de ton aide Mazarini.

Et merci à toi Ghost j'ai exactement fait ta méthode et ça fonctionne bien.

Merci et bonne fin d’après-midi.

Mammouth du PHP | 619 Messages

13 mai 2013, 17:45

Bonjour,

pas de souci d'ailleurs on peux améliorer comme cela car la premier condition n'est pas utile
<?php
$where="";      
if(isset($_POST['nomRapporteur']) and !empty($_POST['nomRapporteur'])){$where.="nomRapporteur = '".$_POST['nomRapporteur']."' and ";}
if(isset($_POST['nomClient']) and !empty($_POST['nomClient'])){$where.="nomClient = '".$_POST['nomClient']."' and ";}
if(isset($_POST['idFiche']) and !empty($_POST['idFiche'])){$where.="idFiche = '".$_POST['idFiche']."' and ";}
if(isset($_POST['dateReclamation']) and !empty($_POST['dateReclamation'])){$where.="dateReclamation >='".$_POST['dateReclamation']."' and ";}

if(!empty($where)){$where = 'where '.substr($where, 0, -4);}

$req = $bd->query("SELECT * from RECHERCHE_RC1 $where");


?>