Tableau croisé dynamique

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : Tableau croisé dynamique

Re: Tableau croisé dynamique

par master2011 » 29 août 2012, 13:53

suite:

<!----------------------------------------- Recherche des données --------------------------------------------->
<?php

$annee = 1900;

//Vérification de la période choisie
if($idb>0 && $ide>0)
{
	//Vérifier que les périodes sont cohérentes
	if($ide < $idb)
	{
		/*Afficher un message d'erreur
		Maintenir le focus sur le fieldset période*/
	}
	//SINON
	else
	{
		//La période choisite est comprise entre date début et une date fin
		if($idd>0)
		{
			$reponse = $bdd->query('SELECT
								  dbvente.periode.An,
								  dbvente.sous_produit_detail.Nom_Sous_Produit_Detail,
								  dbvente.unites.Nom_Unite,
								  dbvente.vente_sous_detail.Volume,
								  dbvente.vente_sous_detail.Prix,
								  dbvente.vente_sous_detail.CA,
								  dbvente.vente_sous_detail.CA_Dinars
								FROM
								  dbvente.vente_sous_detail,
								  dbvente.sous_produit_detail,
								  dbvente.periode,
								  dbvente.produit,
								  dbvente.sous_produit,
								  dbvente.unites,
								  dbvente.famille_produit
								WHERE
								  dbvente.famille_produit.ID_Famille = ' . $idf . ' AND
								  dbvente.produit.ID_Produit = ' . $idp . ' AND
								  dbvente.sous_produit.ID_Sous_Produit = ' . $ids . ' AND
								  dbvente.vente_sous_detail.ID_Marche = 2 AND
								  dbvente.vente_sous_detail.ID_Periode BETWEEN ' .$idb . ' AND ' . $ide . ' AND
								  dbvente.sous_produit_detail.ID_Sous_Produit_Detail = ' . $idd . ' AND
								  dbvente.vente_sous_detail.ID_Periode = dbvente.periode.ID_Periode AND
								  dbvente.vente_sous_detail.ID_Sous_Produit_Detail = dbvente.sous_produit_detail.ID_Sous_Produit_Detail AND
								  dbvente.sous_produit_detail.ID_Sous_Produit = dbvente.sous_produit.ID_Sous_Produit AND
								  dbvente.sous_produit.ID_Produit = dbvente.produit.ID_Produit AND
								  dbvente.vente_sous_detail.ID_Unite = dbvente.unites.ID_Unite AND
								  dbvente.famille_produit.ID_Famille = dbvente.produit.ID_Famille
								ORDER BY
								  dbvente.periode.An DESC');
								  
			?>
			<table border="2" width="100%" cellpadding="3">
				<?php
					//if(!empty($vl) || !empty($pm) || !empty($cd) || !empty($cl)){		
					while ($donnees = $reponse->fetch())
					{
						if($annee != $donnees['An']){
							echo '<tr>';
								echo '<th colspan="6">' . $donnees['An']. '</th>';
								echo '<tr>';
									echo '<th> Sous-Produits </th>';
									echo '<th> Unité </th>';
									//if(!empty($vl))
									{echo '<th>Volume</th>';}
									//if(!empty($pm))
									{echo '<th>Prix Moyen</th>';} 
									if(!empty($cd))
									//{echo '<th>Chiffre affaire devise</th>';} 
									//if(!empty($cl))
									{echo '<th>Chiffre affaire dinars</th>';} 
								echo '</tr>';	
							echo '</tr>';
						}
						
						echo '<tr><td>' . htmlspecialchars($donnees['Nom_Sous_Produit_Detail']) . '</td>';
							echo '<td>' . $donnees['Nom_Unite']. '</td>';	
							echo '<td>' . $donnees['Volume']. '</td>';
							if ($donnees['Prix']!=0){
								echo '<td>' . $donnees['Prix']. '</td>';}else{echo '<td>ND</td>';}
							if ($donnees['CA']!=0){
								echo '<td>' . $donnees['CA']. '</td>';}else{echo '<td>ND</td>';}
							if ($donnees['CA_Dinars']!=0){
								echo '<td>' . $donnees['CA_Dinars']. '</td>';}else{echo '<td>ND</td>';}
							$annee = $donnees['An'];
					}//}
					
				?>
			</table>					
			<?php
		}
		//SINON
		else
		{
			
			if($ids>0)
			{
				/*afficher toutes les ventes réalisées du sous produit
				je manipule à ce niveau la table vente de sous produit
				et la table détail*/
				
				$reponse = $bdd->query('SELECT
									  dbvente.periode.An,
									  dbvente.sous_produit_detail.Nom_Sous_Produit_Detail,
									  dbvente.unites.Nom_Unite,
									  dbvente.vente_sous_detail.Volume,										  
									  dbvente.vente_sous_detail.Prix,
									  dbvente.vente_sous_detail.CA,
									  dbvente.vente_sous_detail.CA_Dinars
									FROM
									  dbvente.vente_sous_detail,
									  dbvente.sous_produit_detail,
									  dbvente.periode,
									  dbvente.produit,
									  dbvente.sous_produit,
									  dbvente.unites,
									  dbvente.famille_produit
									WHERE
									  dbvente.famille_produit.ID_Famille = ' . $idf . ' AND
									  dbvente.produit.ID_Produit = ' . $idp . ' AND
									  dbvente.sous_produit.ID_Sous_Produit = ' . $ids . ' AND
									  dbvente.vente_sous_detail.ID_Periode BETWEEN ' . $idb . ' AND ' . $ide . ' AND										  
									  dbvente.vente_sous_detail.ID_Marche = 2 AND
									  dbvente.vente_sous_detail.ID_Periode = dbvente.periode.ID_Periode AND
									  dbvente.vente_sous_detail.ID_Sous_Produit_Detail = dbvente.sous_produit_detail.ID_Sous_Produit_Detail AND
									  dbvente.sous_produit_detail.ID_Sous_Produit = dbvente.sous_produit.ID_Sous_Produit AND
									  dbvente.sous_produit.ID_Produit = dbvente.produit.ID_Produit AND
									  dbvente.vente_sous_detail.ID_Unite = dbvente.unites.ID_Unite AND
									  dbvente.famille_produit.ID_Famille = dbvente.produit.ID_Famille
									ORDER BY
									  dbvente.periode.An DESC');
									  
				?>
				<table border="2" width="100%" cellpadding="3">
					<?php
								
						while ($donnees = $reponse->fetch())
						{
							if($annee != $donnees['An']){
								echo '<tr>';
									echo '<th colspan="6">' . $donnees['An']. '</th>';
									echo '<tr>';
										echo '<th> Détail Sous-Produits </th>';
										echo '<th> Unité </th>';
										echo '<th>Volume</th>';
										echo '<th>Prix Moyen</th>';
										echo '<th>Chiffre affaire devise</th>';
										echo '<th>Chiffre affaire dinars</th>';	
									echo '</tr>';	
								echo '</tr>';
							}
							
							echo '<tr><td>' . htmlspecialchars($donnees['Nom_Sous_Produit_Detail']) . '</td>';
								echo '<td>' . $donnees['Nom_Unite']. '</td>';	
								echo '<td>' . $donnees['Volume']. '</td>';
								if ($donnees['Prix']!=0){
									echo '<td>' . $donnees['Prix']. '</td>';}else{echo '<td>ND</td>';}
								if ($donnees['CA']!=0){
									echo '<td>' . $donnees['CA']. '</td>';}else{echo '<td>ND</td>';}
								if ($donnees['CA_Dinars']!=0){
									echo '<td>' . $donnees['CA_Dinars']. '</td>';}else{echo '<td>ND</td>';}
								$annee = $donnees['An'];
						}
						
					?>
				</table>				
				<?php
			}
			//SINON
			else
			{
				
				if($idp>0)
				{
					/*afficher toutes les ventes réalisées du produit
					je manipile à ce niveau la table vente globale
					et la table de vente de sous produit*/
					
					$reponse = $bdd->query('SELECT
										  dbvente.periode.An,
										  dbvente.sous_produit.Nom_Sous_Produit,
										  dbvente.unites.Nom_Unite,
										  dbvente.vente_detail.Volume,
										  dbvente.vente_detail.Prix,
										  dbvente.vente_detail.CA,
										  dbvente.vente_detail.CA_Dinars
										FROM
										  dbvente.periode,
										  dbvente.sous_produit,
										  dbvente.vente_detail,
										  dbvente.produit,
										  dbvente.famille_produit,
										  dbvente.unites
										WHERE
										  dbvente.vente_detail.ID_Periode = dbvente.periode.ID_Periode AND
										  dbvente.vente_detail.ID_Sous_Produit = dbvente.sous_produit.ID_Sous_Produit AND
										  dbvente.sous_produit.ID_Produit = dbvente.produit.ID_Produit AND
										  dbvente.produit.ID_Famille = dbvente.famille_produit.ID_Famille AND
										  dbvente.vente_detail.ID_Unite = dbvente.unites.ID_Unite AND
										  dbvente.vente_detail.ID_Marche = 2 AND
										  dbvente.famille_produit.ID_Famille = ' . $idf . ' AND
										  dbvente.sous_produit.ID_Produit = ' . $idp . ' AND
										  dbvente.vente_detail.ID_Periode BETWEEN ' . $idb . ' AND ' . $ide . ' '.'
										ORDER BY
										  dbvente.periode.An DESC');
										  
					?>
					<table border="2" width="100%" cellpadding="3">
						<?php
									
							while ($donnees = $reponse->fetch())
							{
								if($annee != $donnees['An']){
									echo '<tr>';
										echo '<th colspan="6">' . $donnees['An']. '</th>';
										echo '<tr>';
											echo '<th> Sous-Produits </th>';
											echo '<th> Unité </th>';
											echo '<th>Volume</th>';
											echo '<th>Prix Moyen</th>';
											echo '<th>Chiffre affaire devise</th>';
											echo '<th>Chiffre affaire dinars</th>';	
										echo '</tr>';	
									echo '</tr>';
								}
								
								echo '<tr><td>' . htmlspecialchars($donnees['Nom_Sous_Produit']) . '</td>';
									echo '<td>' . $donnees['Nom_Unite']. '</td>';	
									echo '<td>' . $donnees['Volume']. '</td>';
									if ($donnees['Prix']!=0){
										echo '<td>' . $donnees['Prix']. '</td>';}else{echo '<td>ND</td>';}
									if ($donnees['CA']!=0){
										echo '<td>' . $donnees['CA']. '</td>';}else{echo '<td>ND</td>';}
									if ($donnees['CA_Dinars']!=0){
										echo '<td>' . $donnees['CA_Dinars']. '</td>';}else{echo '<td>ND</td>';}
									$annee = $donnees['An'];
							}
							
						?>
					</table>
				
					<?php
				}
				else
				{
					if($idf>0)
					{
						/*afficher toutes les ventes réalisées de la famille 
						je manipile à ce niveau la table vente globale*/
						
						$reponse = $bdd->query('SELECT
											  dbvente.periode.An,
											  dbvente.produit.Nom_Produit,
											  dbvente.unites.Nom_Unite,
											  dbvente.vente.Volume,
											  dbvente.vente.Prix,
											  dbvente.vente.CA,
											  dbvente.vente.CA_Dinars
											FROM
											  dbvente.periode,
											  dbvente.produit,
											  dbvente.vente,
											  dbvente.unites
											WHERE
											  dbvente.vente.ID_Periode = dbvente.periode.ID_Periode AND
											  dbvente.vente.ID_Produit = dbvente.produit.ID_Produit AND
											  dbvente.vente.ID_Unite = dbvente.unites.ID_Unite AND
											  dbvente.vente.ID_Marche = 2 AND
											  dbvente.vente.ID_Famille = ' . $idf . ' ' . 'AND
											  dbvente.vente.ID_Periode BETWEEN ' . $idb . ' AND '. $ide .' '.'
											ORDER BY
											  dbvente.periode.An DESC');
						?>
						
						<table border="2" width="100%" cellpadding="3">
							<?php
										
								while ($donnees = $reponse->fetch())
								{
									if($annee != $donnees['An']){
										echo '<tr>';
											echo '<th colspan="6">' . $donnees['An']. '</th>';
											echo '<tr>';
												echo '<th> Produit </th>';
												echo '<th> Unité </th>';
												echo '<th>Volume</th>';
												echo '<th>Prix Moyen</th>';
												echo '<th>Chiffre affaire devise</th>';
												echo '<th>Chiffre affaire dinars</th>';	
											echo '</tr>';	
										echo '</tr>';
									}
									
									echo '<tr><td>' . htmlspecialchars($donnees['Nom_Produit']) . '</td>';
										echo '<td>' . $donnees['Nom_Unite']. '</td>';	
										echo '<td>' . $donnees['Volume']. '</td>';
										if ($donnees['Prix']!=0){
											echo '<td>' . $donnees['Prix']. '</td>';}else{echo '<td>ND</td>';}
										if ($donnees['CA']!=0){
											echo '<td>' . $donnees['CA']. '</td>';}else{echo '<td>ND</td>';}
										if ($donnees['CA_Dinars']!=0){
											echo '<td>' . $donnees['CA_Dinars']. '</td>';}else{echo '<td>ND</td>';}
										$annee = $donnees['An'];
								}
								
							?>
						</table>
						
						<?php
					}
				}
			}
		}
	}
}
/*Sinon
 Vérifier les intervales choisis*/
else
{
	//La période choisie correspond à depuis une date début jusqu'à présent
	if($idb>0 && $ide<=0)
	{
		if($idd>0)
		{
			$reponse = $bdd->query('SELECT
								  dbvente.periode.An,
								  dbvente.sous_produit_detail.Nom_Sous_Produit_Detail,
								  dbvente.unites.Nom_Unite,
								  dbvente.vente_sous_detail.Volume,
								  dbvente.vente_sous_detail.Prix,
								  dbvente.vente_sous_detail.CA,
								  dbvente.vente_sous_detail.CA_Dinars
								FROM
								  dbvente.vente_sous_detail,
								  dbvente.sous_produit_detail,
								  dbvente.periode,
								  dbvente.produit,
								  dbvente.sous_produit,
								  dbvente.unites,
								  dbvente.famille_produit
								WHERE
								  dbvente.famille_produit.ID_Famille = ' . $idf . ' AND
								  dbvente.produit.ID_Produit = ' . $idp . ' AND
								  dbvente.sous_produit.ID_Sous_Produit = ' . $ids . ' AND
								  dbvente.vente_sous_detail.ID_Marche = 2 AND
								  dbvente.vente_sous_detail.ID_Periode >= ' .$idb . ' ' . '
								  dbvente.sous_produit_detail.ID_Sous_Produit_Detail = ' . $idd . ' AND
								  dbvente.vente_sous_detail.ID_Periode = dbvente.periode.ID_Periode AND
								  dbvente.vente_sous_detail.ID_Sous_Produit_Detail = dbvente.sous_produit_detail.ID_Sous_Produit_Detail AND
								  dbvente.sous_produit_detail.ID_Sous_Produit = dbvente.sous_produit.ID_Sous_Produit AND
								  dbvente.sous_produit.ID_Produit = dbvente.produit.ID_Produit AND
								  dbvente.vente_sous_detail.ID_Unite = dbvente.unites.ID_Unite AND
								  dbvente.famille_produit.ID_Famille = dbvente.produit.ID_Famille
								ORDER BY
								  dbvente.periode.An DESC');
								  
			?>
			<table border="2" width="100%" cellpadding="3">
				<?php
							
					while ($donnees = $reponse->fetch())
					{
						if($annee != $donnees['An']){
							echo '<tr>';
								echo '<th colspan="6">' . $donnees['An']. '</th>';
								echo '<tr>';
									echo '<th> Sous-Produits </th>';
									echo '<th> Unité </th>';
									echo '<th>Volume</th>';
									echo '<th>Prix Moyen</th>';
									echo '<th>Chiffre affaire devise</th>';
									echo '<th>Chiffre affaire dinars</th>';	
								echo '</tr>';	
							echo '</tr>';
						}
						
						echo '<tr><td>' . htmlspecialchars($donnees['Nom_Sous_Produit_Detail']) . '</td>';
							echo '<td>' . $donnees['Nom_Unite']. '</td>';	
							echo '<td>' . $donnees['Volume']. '</td>';
							if ($donnees['Prix']!=0){
								echo '<td>' . $donnees['Prix']. '</td>';}else{echo '<td>ND</td>';}
							if ($donnees['CA']!=0){
								echo '<td>' . $donnees['CA']. '</td>';}else{echo '<td>ND</td>';}
							if ($donnees['CA_Dinars']!=0){
								echo '<td>' . $donnees['CA_Dinars']. '</td>';}else{echo '<td>ND</td>';}
							$annee = $donnees['An'];
					}
					
				?>
			</table>					
			<?php
		}
		//SINON
		else
		{
			 //SI produit selectionné ALORS
			if($ids>0)
			{
				/*afficher toutes les ventes réalisées du sous produit
				je manipule à ce niveau la table vente de sous produit
				et la table détail*/
				
				$reponse = $bdd->query('SELECT
									  dbvente.periode.An,
									  dbvente.sous_produit_detail.Nom_Sous_Produit_Detail,
									  dbvente.unites.Nom_Unite,
									  dbvente.vente_sous_detail.Volume,										  
									  dbvente.vente_sous_detail.Prix,
									  dbvente.vente_sous_detail.CA,
									  dbvente.vente_sous_detail.CA_Dinars
									FROM
									  dbvente.vente_sous_detail,
									  dbvente.sous_produit_detail,
									  dbvente.periode,
									  dbvente.produit,
									  dbvente.sous_produit,
									  dbvente.unites,
									  dbvente.famille_produit
									WHERE
									  dbvente.famille_produit.ID_Famille = ' . $idf . ' AND
									  dbvente.produit.ID_Produit = ' . $idp . ' AND
									  dbvente.sous_produit.ID_Sous_Produit = ' . $ids . ' AND
									  dbvente.vente_sous_detail.ID_Periode >= ' . $idb . ' ' . '										  
									  dbvente.vente_sous_detail.ID_Marche = 2 AND
									  dbvente.vente_sous_detail.ID_Periode = dbvente.periode.ID_Periode AND
									  dbvente.vente_sous_detail.ID_Sous_Produit_Detail = dbvente.sous_produit_detail.ID_Sous_Produit_Detail AND
									  dbvente.sous_produit_detail.ID_Sous_Produit = dbvente.sous_produit.ID_Sous_Produit AND
									  dbvente.sous_produit.ID_Produit = dbvente.produit.ID_Produit AND
									  dbvente.vente_sous_detail.ID_Unite = dbvente.unites.ID_Unite AND
									  dbvente.famille_produit.ID_Famille = dbvente.produit.ID_Famille
									ORDER BY
									  dbvente.periode.An DESC');
				
				?>
				<table border="2" width="100%" cellpadding="3">
					<?php
								
						while ($donnees = $reponse->fetch())
						{
							if($annee != $donnees['An']){
								echo '<tr>';
									echo '<th colspan="6">' . $donnees['An']. '</th>';
									echo '<tr>';
										echo '<th> Sous-Produits </th>';
										echo '<th> Unité </th>';
										echo '<th>Volume</th>';
										echo '<th>Prix Moyen</th>';
										echo '<th>Chiffre affaire devise</th>';
										echo '<th>Chiffre affaire dinars</th>';	
									echo '</tr>';	
								echo '</tr>';
							}
							
							echo '<tr><td>' . htmlspecialchars($donnees['Nom_Sous_Produit_Detail']) . '</td>';
								echo '<td>' . $donnees['Nom_Unite']. '</td>';	
								echo '<td>' . $donnees['Volume']. '</td>';
								if ($donnees['Prix']!=0){
									echo '<td>' . $donnees['Prix']. '</td>';}else{echo '<td>ND</td>';}
								if ($donnees['CA']!=0){
									echo '<td>' . $donnees['CA']. '</td>';}else{echo '<td>ND</td>';}
								if ($donnees['CA_Dinars']!=0){
									echo '<td>' . $donnees['CA_Dinars']. '</td>';}else{echo '<td>ND</td>';}
								$annee = $donnees['An'];
						}
						
					?>
				</table>				
				<?php
			}
			//SINON
			else
			{
				//SI sous produit selectionné ALORS
				if($idp>0)
				{
					/*afficher toutes les ventes réalisées du produit
					je manipile à ce niveau la table vente globale
					et la table de vente de sous produit*/
					
					$reponse = $bdd->query('SELECT
										  dbvente.periode.An,
										  dbvente.sous_produit.Nom_Sous_Produit,
										  dbvente.unites.Nom_Unite,
										  dbvente.vente_detail.Volume,
										  dbvente.vente_detail.Prix,
										  dbvente.vente_detail.CA,
										  dbvente.vente_detail.CA_Dinars
										FROM
										  dbvente.periode,
										  dbvente.sous_produit,
										  dbvente.vente_detail,
										  dbvente.produit,
										  dbvente.famille_produit,
										  dbvente.unites
										WHERE
										  dbvente.vente_detail.ID_Periode = dbvente.periode.ID_Periode AND
										  dbvente.vente_detail.ID_Sous_Produit = dbvente.sous_produit.ID_Sous_Produit AND
										  dbvente.sous_produit.ID_Produit = dbvente.produit.ID_Produit AND
										  dbvente.produit.ID_Famille = dbvente.famille_produit.ID_Famille AND
										  dbvente.vente_detail.ID_Unite = dbvente.unites.ID_Unite AND
										  dbvente.vente_detail.ID_Marche = 2 AND
										  dbvente.famille_produit.ID_Famille = ' . $idf . ' AND
										  dbvente.sous_produit.ID_Produit = ' . $idp . ' AND
										  dbvente.vente_detail.ID_Periode >= ' . $idb . ' ' .'
										ORDER BY
										  dbvente.periode.An DESC');
										  
					
					?>
					<table border="2" width="100%" cellpadding="3">
						<?php
									
							while ($donnees = $reponse->fetch())
							{
								if($annee != $donnees['An']){
									echo '<tr>';
										echo '<th colspan="6">' . $donnees['An']. '</th>';
										echo '<tr>';
											echo '<th> Sous-Produits </th>';
											echo '<th> Unité </th>';
											echo '<th>Volume</th>';
											echo '<th>Prix Moyen</th>';
											echo '<th>Chiffre affaire devise</th>';
											echo '<th>Chiffre affaire dinars</th>';	
										echo '</tr>';	
									echo '</tr>';
								}
								
								echo '<tr><td>' . htmlspecialchars($donnees['Nom_Sous_Produit']) . '</td>';
									echo '<td>' . $donnees['Nom_Unite']. '</td>';	
									echo '<td>' . $donnees['Volume']. '</td>';
									if ($donnees['Prix']!=0){
										echo '<td>' . $donnees['Prix']. '</td>';}else{echo '<td>ND</td>';}
									if ($donnees['CA']!=0){
										echo '<td>' . $donnees['CA']. '</td>';}else{echo '<td>ND</td>';}
									if ($donnees['CA_Dinars']!=0){
										echo '<td>' . $donnees['CA_Dinars']. '</td>';}else{echo '<td>ND</td>';}
									$annee = $donnees['An'];
							}
							
						?>
					</table>				
					<?php
				}
				else
				{
					if($idf>0)
					{
						/*afficher toutes les ventes réalisées de la famille 
						je manipile à ce niveau la table vente globale*/
						
						$reponse = $bdd->query('SELECT
											  dbvente.periode.An,
											  dbvente.produit.Nom_Produit,
											  dbvente.unites.Nom_Unite,
											  dbvente.vente.Volume,
											  dbvente.vente.Prix,
											  dbvente.vente.CA,
											  dbvente.vente.CA_Dinars
											FROM
											  dbvente.periode,
											  dbvente.produit,
											  dbvente.vente,
											  dbvente.unites
											WHERE
											  dbvente.vente.ID_Periode = dbvente.periode.ID_Periode AND
											  dbvente.vente.ID_Produit = dbvente.produit.ID_Produit AND
											  dbvente.vente.ID_Unite = dbvente.unites.ID_Unite AND
											  dbvente.vente.ID_Marche = 2 AND
											  dbvente.vente.ID_Famille = ' . $idf . ' ' . 'AND
											  dbvente.vente.ID_Periode >= ' . $idb . ' '.'
											ORDER BY
											  dbvente.periode.An DESC');
											  
						?>
						
						<table border="2" width="100%" cellpadding="3">
							<?php
										
								while ($donnees = $reponse->fetch())
								{
									if($annee != $donnees['An']){
										echo '<tr>';
											echo '<th colspan="6">' . $donnees['An']. '</th>';
											echo '<tr>';
												echo '<th> Produit </th>';
												echo '<th> Unité </th>';
												echo '<th>Volume</th>';
												echo '<th>Prix Moyen</th>';
												echo '<th>Chiffre affaire devise</th>';
												echo '<th>Chiffre affaire dinars</th>';	
											echo '</tr>';	
										echo '</tr>';
									}
									
									echo '<tr><td>' . htmlspecialchars($donnees['Nom_Produit']) . '</td>';
										echo '<td>' . $donnees['Nom_Unite']. '</td>';	
										echo '<td>' . $donnees['Volume']. '</td>';
										if ($donnees['Prix']!=0){
											echo '<td>' . $donnees['Prix']. '</td>';}else{echo '<td>ND</td>';}
										if ($donnees['CA']!=0){
											echo '<td>' . $donnees['CA']. '</td>';}else{echo '<td>ND</td>';}
										if ($donnees['CA_Dinars']!=0){
											echo '<td>' . $donnees['CA_Dinars']. '</td>';}else{echo '<td>ND</td>';}
										$annee = $donnees['An'];
								}
								
							?>
						</table>
						
						<?php
					}
				}
			}
		}
	}
	else
	{
		if($idb<=0 && $ide>0)
		{
			//La période choisie correspond à toutes les dates jusqu'à une date précise
			if($idd>0)
			{
				$reponse = $bdd->query('SELECT
									  dbvente.periode.An,
									  dbvente.sous_produit_detail.Nom_Sous_Produit_Detail,
									  dbvente.unites.Nom_Unite,
									  dbvente.vente_sous_detail.Volume,
									  dbvente.vente_sous_detail.Prix,
									  dbvente.vente_sous_detail.CA,
									  dbvente.vente_sous_detail.CA_Dinars
									FROM
									  dbvente.vente_sous_detail,
									  dbvente.sous_produit_detail,
									  dbvente.periode,
									  dbvente.produit,
									  dbvente.sous_produit,
									  dbvente.unites,
									  dbvente.famille_produit
									WHERE
									  dbvente.famille_produit.ID_Famille = ' . $idf . ' AND
									  dbvente.produit.ID_Produit = ' . $idp . ' AND
									  dbvente.sous_produit.ID_Sous_Produit = ' . $ids . ' AND
									  dbvente.vente_sous_detail.ID_Marche = 2 AND
									  dbvente.vente_sous_detail.ID_Periode <= ' .$ide . ' ' . '
									  dbvente.sous_produit_detail.ID_Sous_Produit_Detail = ' . $idd . ' AND
									  dbvente.vente_sous_detail.ID_Periode = dbvente.periode.ID_Periode AND
									  dbvente.vente_sous_detail.ID_Sous_Produit_Detail = dbvente.sous_produit_detail.ID_Sous_Produit_Detail AND
									  dbvente.sous_produit_detail.ID_Sous_Produit = dbvente.sous_produit.ID_Sous_Produit AND
									  dbvente.sous_produit.ID_Produit = dbvente.produit.ID_Produit AND
									  dbvente.vente_sous_detail.ID_Unite = dbvente.unites.ID_Unite AND
									  dbvente.famille_produit.ID_Famille = dbvente.produit.ID_Famille
									ORDER BY
									  dbvente.periode.An DESC');
									  
				?>
				<table border="2" width="100%" cellpadding="3">
					<?php
								
						while ($donnees = $reponse->fetch())
						{
							if($annee != $donnees['An']){
								echo '<tr>';
									echo '<th colspan="6">' . $donnees['An']. '</th>';
									echo '<tr>';
										echo '<th> Sous-Produits </th>';
										echo '<th> Unité </th>';
										echo '<th>Volume</th>';
										echo '<th>Prix Moyen</th>';
										echo '<th>Chiffre affaire devise</th>';
										echo '<th>Chiffre affaire dinars</th>';	
									echo '</tr>';	
								echo '</tr>';
							}
							
							echo '<tr><td>' . htmlspecialchars($donnees['Nom_Sous_Produit_Detail']) . '</td>';
								echo '<td>' . $donnees['Nom_Unite']. '</td>';	
								echo '<td>' . $donnees['Volume']. '</td>';
								if ($donnees['Prix']!=0){
									echo '<td>' . $donnees['Prix']. '</td>';}else{echo '<td>ND</td>';}
								if ($donnees['CA']!=0){
									echo '<td>' . $donnees['CA']. '</td>';}else{echo '<td>ND</td>';}
								if ($donnees['CA_Dinars']!=0){
									echo '<td>' . $donnees['CA_Dinars']. '</td>';}else{echo '<td>ND</td>';}
								$annee = $donnees['An'];
						}
						
					?>
				</table>					
				<?php
			}
			//SINON
			else
			{
				 //SI produit selectionné ALORS
				if($ids>0)
				{
					/*afficher toutes les ventes réalisées du sous produit
					je manipule à ce niveau la table vente de sous produit
					et la table détail*/
					
					$reponse = $bdd->query('SELECT
									  dbvente.periode.An,
									  dbvente.sous_produit_detail.Nom_Sous_Produit_Detail,
									  dbvente.unites.Nom_Unite,
									  dbvente.vente_sous_detail.Volume,										  
									  dbvente.vente_sous_detail.Prix,
									  dbvente.vente_sous_detail.CA,
									  dbvente.vente_sous_detail.CA_Dinars
									FROM
									  dbvente.vente_sous_detail,
									  dbvente.sous_produit_detail,
									  dbvente.periode,
									  dbvente.produit,
									  dbvente.sous_produit,
									  dbvente.unites,
									  dbvente.famille_produit
									WHERE
									  dbvente.famille_produit.ID_Famille = ' . $idf . ' AND
									  dbvente.produit.ID_Produit = ' . $idp . ' AND
									  dbvente.sous_produit.ID_Sous_Produit = ' . $ids . ' AND
									  dbvente.vente_sous_detail.ID_Periode <= ' . $ide . ' ' . '										  
									  dbvente.vente_sous_detail.ID_Marche = 2 AND
									  dbvente.vente_sous_detail.ID_Periode = dbvente.periode.ID_Periode AND
									  dbvente.vente_sous_detail.ID_Sous_Produit_Detail = dbvente.sous_produit_detail.ID_Sous_Produit_Detail AND
									  dbvente.sous_produit_detail.ID_Sous_Produit = dbvente.sous_produit.ID_Sous_Produit AND
									  dbvente.sous_produit.ID_Produit = dbvente.produit.ID_Produit AND
									  dbvente.vente_sous_detail.ID_Unite = dbvente.unites.ID_Unite AND
									  dbvente.famille_produit.ID_Famille = dbvente.produit.ID_Famille
									ORDER BY
									  dbvente.periode.An DESC');
									  
					?>
					<table border="2" width="100%" cellpadding="3">
						<?php
									
							while ($donnees = $reponse->fetch())
							{
								if($annee != $donnees['An']){
									echo '<tr>';
										echo '<th colspan="6">' . $donnees['An']. '</th>';
										echo '<tr>';
											echo '<th> Sous-Produits </th>';
											echo '<th> Unité </th>';
											echo '<th>Volume</th>';
											echo '<th>Prix Moyen</th>';
											echo '<th>Chiffre affaire devise</th>';
											echo '<th>Chiffre affaire dinars</th>';	
										echo '</tr>';	
									echo '</tr>';
								}
								
								echo '<tr><td>' . htmlspecialchars($donnees['Nom_Sous_Produit_Detail']) . '</td>';
									echo '<td>' . $donnees['Nom_Unite']. '</td>';	
									echo '<td>' . $donnees['Volume']. '</td>';
									if ($donnees['Prix']!=0){
										echo '<td>' . $donnees['Prix']. '</td>';}else{echo '<td>ND</td>';}
									if ($donnees['CA']!=0){
										echo '<td>' . $donnees['CA']. '</td>';}else{echo '<td>ND</td>';}
									if ($donnees['CA_Dinars']!=0){
										echo '<td>' . $donnees['CA_Dinars']. '</td>';}else{echo '<td>ND</td>';}
									$annee = $donnees['An'];
							}
							
						?>
					</table>					
					<?php
				}
				//SINON
				else
				{
					//SI sous produit selectionné ALORS
					if($idp>0)
					{
						/*afficher toutes les ventes réalisées du produit
						je manipile à ce niveau la table vente globale
						et la table de vente de sous produit*/
						
						$reponse = $bdd->query('SELECT
										  dbvente.periode.An,
										  dbvente.sous_produit.Nom_Sous_Produit,
										  dbvente.unites.Nom_Unite,
										  dbvente.vente_detail.Volume,
										  dbvente.vente_detail.Prix,
										  dbvente.vente_detail.CA,
										  dbvente.vente_detail.CA_Dinars
										FROM
										  dbvente.periode,
										  dbvente.sous_produit,
										  dbvente.vente_detail,
										  dbvente.produit,
										  dbvente.famille_produit,
										  dbvente.unites
										WHERE
										  dbvente.vente_detail.ID_Periode = dbvente.periode.ID_Periode AND
										  dbvente.vente_detail.ID_Sous_Produit = dbvente.sous_produit.ID_Sous_Produit AND
										  dbvente.sous_produit.ID_Produit = dbvente.produit.ID_Produit AND
										  dbvente.produit.ID_Famille = dbvente.famille_produit.ID_Famille AND
										  dbvente.vente_detail.ID_Unite = dbvente.unites.ID_Unite AND
										  dbvente.vente_detail.ID_Marche = 2 AND
										  dbvente.famille_produit.ID_Famille = ' . $idf . ' AND
										  dbvente.sous_produit.ID_Produit = ' . $idp . ' AND
										  dbvente.vente_detail.ID_Periode <= ' . $ide . ' ' .'
										ORDER BY
										  dbvente.periode.An DESC');
										  
							?>
						<table border="2" width="100%" cellpadding="3">
							<?php
										
								while ($donnees = $reponse->fetch())
								{
									if($annee != $donnees['An']){
										echo '<tr>';
											echo '<th colspan="6">' . $donnees['An']. '</th>';
											echo '<tr>';
												echo '<th> Sous-Produits </th>';
												echo '<th> Unité </th>';
												echo '<th>Volume</th>';
												echo '<th>Prix Moyen</th>';
												echo '<th>Chiffre affaire devise</th>';
												echo '<th>Chiffre affaire dinars</th>';	
											echo '</tr>';	
										echo '</tr>';
									}
									
									echo '<tr><td>' . htmlspecialchars($donnees['Nom_Sous_Produit']) . '</td>';
										echo '<td>' . $donnees['Nom_Unite']. '</td>';	
										echo '<td>' . $donnees['Volume']. '</td>';
										if ($donnees['Prix']!=0){
											echo '<td>' . $donnees['Prix']. '</td>';}else{echo '<td>ND</td>';}
										if ($donnees['CA']!=0){
											echo '<td>' . $donnees['CA']. '</td>';}else{echo '<td>ND</td>';}
										if ($donnees['CA_Dinars']!=0){
											echo '<td>' . $donnees['CA_Dinars']. '</td>';}else{echo '<td>ND</td>';}
										$annee = $donnees['An'];
								}
								
							?>
						</table>					
						<?php
					}
					else
					{
						if($idf>0)
						{
							/*afficher toutes les ventes réalisées de la famille 
							je manipile à ce niveau la table vente globale*/
							
							$reponse = $bdd->query('SELECT
												  dbvente.periode.An,
												  dbvente.produit.Nom_Produit,
												  dbvente.unites.ID_Unite,
												  dbvente.vente.Volume,
												  dbvente.vente.Prix,
												  dbvente.vente.CA,
												  dbvente.vente.CA_Dinars
												FROM
												  dbvente.periode,
												  dbvente.produit,
												  dbvente.vente,
												  dbvente.unites
												WHERE
												  dbvente.vente.ID_Periode = dbvente.periode.ID_Periode AND
												  dbvente.vente.ID_Produit = dbvente.produit.ID_Produit AND
												  dbvente.vente.ID_unite = dbvente.unites.ID_Unite AND
												  dbvente.vente.ID_Marche = 2 AND
												  dbvente.vente.ID_Famille = ' . $idf . ' ' . 'AND
												  dbvente.vente.ID_Periode <= ' . $ide . ' '.'
												ORDER BY
												  dbvente.periode.An DESC');

							?>
						
							<table border="2" width="100%" cellpadding="3">
								<?php
											
									while ($donnees = $reponse->fetch())
									{
										if($annee != $donnees['An']){
											echo '<tr>';
												echo '<th colspan="6">' . $donnees['An']. '</th>';
												echo '<tr>';
													echo '<th> Produit </th>';
													echo '<th> Unité </th>';
													echo '<th>Volume</th>';
													echo '<th>Prix Moyen</th>';
													echo '<th>Chiffre affaire devise</th>';
													echo '<th>Chiffre affaire dinars</th>';	
												echo '</tr>';	
											echo '</tr>';
										}
										
										echo '<tr><td>' . htmlspecialchars($donnees['Nom_Produit']) . '</td>';
											echo '<td>' . $donnees['Nom_Unite']. '</td>';	
											echo '<td>' . $donnees['Volume']. '</td>';
											if ($donnees['Prix']!=0){
												echo '<td>' . $donnees['Prix']. '</td>';}else{echo '<td>ND</td>';}
											if ($donnees['CA']!=0){
												echo '<td>' . $donnees['CA']. '</td>';}else{echo '<td>ND</td>';}
											if ($donnees['CA_Dinars']!=0){
												echo '<td>' . $donnees['CA_Dinars']. '</td>';}else{echo '<td>ND</td>';}
											$annee = $donnees['An'];
									}
									
								?>
							</table>
							
							<?php
						}
					}
				}
			}
		}
		//SINON
		else{
			/*A ce niveau tout l'historique est à prendre en considération*/
			
			if($idd>0)
			{
				$reponse = $bdd->query('SELECT
									  dbvente.periode.An,
									  dbvente.sous_produit_detail.Nom_Sous_Produit_Detail,
									  dbvente.unites.Nom_Unite,
									  dbvente.vente_sous_detail.Volume,
									  dbvente.vente_sous_detail.Prix,
									  dbvente.vente_sous_detail.CA,
									  dbvente.vente_sous_detail.CA_Dinars
									FROM
									  dbvente.vente_sous_detail,
									  dbvente.sous_produit_detail,
									  dbvente.periode,
									  dbvente.produit,
									  dbvente.sous_produit,
									  dbvente.unites,
									  dbvente.famille_produit
									WHERE
									  dbvente.famille_produit.ID_Famille = ' . $idf . ' AND
									  dbvente.produit.ID_Produit = ' . $idp . ' AND
									  dbvente.sous_produit.ID_Sous_Produit = ' . $ids . ' AND
									  dbvente.vente_sous_detail.ID_Marche = 2 AND 
									  dbvente.sous_produit_detail.ID_Sous_Produit_Detail = ' . $idd . ' AND
									  dbvente.vente_sous_detail.ID_Periode = dbvente.periode.ID_Periode AND
									  dbvente.vente_sous_detail.ID_Sous_Produit_Detail = dbvente.sous_produit_detail.ID_Sous_Produit_Detail AND
									  dbvente.sous_produit_detail.ID_Sous_Produit = dbvente.sous_produit.ID_Sous_Produit AND
									  dbvente.sous_produit.ID_Produit = dbvente.produit.ID_Produit AND
									  dbvente.vente_sous_detail.ID_Unite = dbvente.unites.ID_Unite AND
									  dbvente.famille_produit.ID_Famille = dbvente.produit.ID_Famille
									ORDER BY
									  dbvente.periode.An DESC');
									  
				?>
				<table border="2" width="100%" cellpadding="3">
					<?php
								
						while ($donnees = $reponse->fetch())
						{
							if($annee != $donnees['An']){
								echo '<tr>';
									echo '<th colspan="6">' . $donnees['An']. '</th>';
									echo '<tr>';
										echo '<th> Sous-Produits </th>';
										echo '<th> Unité </th>';
										echo '<th>Volume</th>';
										echo '<th>Prix Moyen</th>';
										echo '<th>Chiffre affaire devise</th>';
										echo '<th>Chiffre affaire dinars</th>';	
									echo '</tr>';	
								echo '</tr>';
							}
							
							echo '<tr><td>' . htmlspecialchars($donnees['Nom_Sous_Produit_Detail']) . '</td>';
								echo '<td>' . $donnees['Nom_Unite']. '</td>';	
								echo '<td>' . $donnees['Volume']. '</td>';
								if ($donnees['Prix']!=0){
									echo '<td>' . $donnees['Prix']. '</td>';}else{echo '<td>ND</td>';}
								if ($donnees['CA']!=0){
									echo '<td>' . $donnees['CA']. '</td>';}else{echo '<td>ND</td>';}
								if ($donnees['CA_Dinars']!=0){
									echo '<td>' . $donnees['CA_Dinars']. '</td>';}else{echo '<td>ND</td>';}
								$annee = $donnees['An'];
						}
						
					?>
				</table>					
				<?php
			}
			//SINON
			else
			{
				 //SI produit selectionné ALORS
				if($ids>0)
				{
					/*afficher toutes les ventes réalisées du sous produit
					je manipule à ce niveau la table vente de sous produit
					et la table détail*/
					
					$reponse = $bdd->query('SELECT
									  dbvente.periode.An,
									  dbvente.sous_produit_detail.Nom_Sous_Produit_Detail,
									  dbvente.unites.Nom_Unite,
									  dbvente.vente_sous_detail.Volume,										  
									  dbvente.vente_sous_detail.Prix,
									  dbvente.vente_sous_detail.CA,
									  dbvente.vente_sous_detail.CA_Dinars
									FROM
									  dbvente.vente_sous_detail,
									  dbvente.sous_produit_detail,
									  dbvente.periode,
									  dbvente.produit,
									  dbvente.sous_produit,
									  dbvente.unites,
									  dbvente.famille_produit
									WHERE
									  dbvente.famille_produit.ID_Famille = ' . $idf . ' AND
									  dbvente.produit.ID_Produit = ' . $idp . ' AND
									  dbvente.sous_produit.ID_Sous_Produit = ' . $ids . ' AND										  
									  dbvente.vente_sous_detail.ID_Marche = 2 AND
									  dbvente.vente_sous_detail.ID_Periode = dbvente.periode.ID_Periode AND
									  dbvente.vente_sous_detail.ID_Sous_Produit_Detail = dbvente.sous_produit_detail.ID_Sous_Produit_Detail AND
									  dbvente.sous_produit_detail.ID_Sous_Produit = dbvente.sous_produit.ID_Sous_Produit AND
									  dbvente.sous_produit.ID_Produit = dbvente.produit.ID_Produit AND
									  dbvente.vente_sous_detail.ID_Unite = dbvente.unites.ID_Unite AND
									  dbvente.famille_produit.ID_Famille = dbvente.produit.ID_Famille
									ORDER BY
									  dbvente.periode.An DESC');
									  
					?>
					<table border="2" width="100%" cellpadding="3">
						<?php
									
							while ($donnees = $reponse->fetch())
							{
								if($annee != $donnees['An']){
									echo '<tr>';
										echo '<th colspan="6">' . $donnees['An']. '</th>';
										echo '<tr>';
											echo '<th> Sous-Produits </th>';
											echo '<th> Unité </th>';
											echo '<th>Volume</th>';
											echo '<th>Prix Moyen</th>';
											echo '<th>Chiffre affaire devise</th>';
											echo '<th>Chiffre affaire dinars</th>';	
										echo '</tr>';	
									echo '</tr>';
								}
								
								echo '<tr><td>' . htmlspecialchars($donnees['Nom_Sous_Produit_Detail']) . '</td>';
									echo '<td>' . $donnees['Nom_Unite']. '</td>';	
									echo '<td>' . $donnees['Volume']. '</td>';
									if ($donnees['Prix']!=0){
										echo '<td>' . $donnees['Prix']. '</td>';}else{echo '<td>ND</td>';}
									if ($donnees['CA']!=0){
										echo '<td>' . $donnees['CA']. '</td>';}else{echo '<td>ND</td>';}
									if ($donnees['CA_Dinars']!=0){
										echo '<td>' . $donnees['CA_Dinars']. '</td>';}else{echo '<td>ND</td>';}
									$annee = $donnees['An'];
							}
							
						?>
					</table>					
					<?php
				}
				//SINON
				else
				{
					//SI sous produit selectionné ALORS
					if($idp>0)
					{
						/*afficher toutes les ventes réalisées du produit
						je manipile à ce niveau la table vente globale
						et la table de vente de sous produit*/
						
						$reponse = $bdd->query('SELECT
										  dbvente.periode.An,
										  dbvente.sous_produit.Nom_Sous_Produit,
										  dbvente.unites.Nom_Unite,
										  dbvente.vente_detail.Volume,
										  dbvente.vente_detail.Prix,
										  dbvente.vente_detail.CA,
										  dbvente.vente_detail.CA_Dinars
										FROM
										  dbvente.periode,
										  dbvente.sous_produit,
										  dbvente.vente_detail,
										  dbvente.produit,
										  dbvente.famille_produit,
										  dbvente.unites
										WHERE
										  dbvente.vente_detail.ID_Periode = dbvente.periode.ID_Periode AND
										  dbvente.vente_detail.ID_Sous_Produit = dbvente.sous_produit.ID_Sous_Produit AND
										  dbvente.sous_produit.ID_Produit = dbvente.produit.ID_Produit AND
										  dbvente.produit.ID_Famille = dbvente.famille_produit.ID_Famille AND
										  dbvente.vente_detail.ID_Unite = dbvente.unites.ID_Unite AND
										  dbvente.vente_detail.ID_Marche = 2 AND
										  dbvente.famille_produit.ID_Famille = ' . $idf . ' AND
										  dbvente.sous_produit.ID_Produit = ' . $idp . ' '.'
										ORDER BY
										  dbvente.periode.An DESC');
										  
						?>
						<table border="2" width="100%" cellpadding="3">
							<?php
										
								while ($donnees = $reponse->fetch())
								{
									if($annee != $donnees['An']){
										echo '<tr>';
											echo '<th colspan="6">' . $donnees['An']. '</th>';
											echo '<tr>';
												echo '<th> Sous-Produits </th>';
												echo '<th> Unité </th>';
												echo '<th>Volume</th>';
												echo '<th>Prix Moyen</th>';
												echo '<th>Chiffre affaire devise</th>';
												echo '<th>Chiffre affaire dinars</th>';	
											echo '</tr>';	
										echo '</tr>';
									}
									
									echo '<tr><td>' . htmlspecialchars($donnees['Nom_Sous_Produit']) . '</td>';
										echo '<td>' . $donnees['Nom_Unite']. '</td>';	
										echo '<td>' . $donnees['Volume']. '</td>';
										if ($donnees['Prix']!=0){
											echo '<td>' . $donnees['Prix']. '</td>';}else{echo '<td>ND</td>';}
										if ($donnees['CA']!=0){
											echo '<td>' . $donnees['CA']. '</td>';}else{echo '<td>ND</td>';}
										if ($donnees['CA_Dinars']!=0){
											echo '<td>' . $donnees['CA_Dinars']. '</td>';}else{echo '<td>ND</td>';}
										$annee = $donnees['An'];
								}
								
							?>
						</table>
					
						<?php
					}
					else
					{
						if($idf>0)
						{
							/*afficher toutes les ventes réalisées de la famille 
							je manipile à ce niveau la table vente globale*/
							
							$reponse = $bdd->query('SELECT
												  dbvente.periode.An,
												  dbvente.produit.Nom_Produit,
												  dbvente.unites.Nom_Unite,
												  dbvente.vente.Volume,
												  dbvente.vente.Prix,
												  dbvente.vente.CA,
												  dbvente.vente.CA_Dinars
												FROM
												  dbvente.periode,
												  dbvente.produit,
												  dbvente.vente,
												  dbvente.unites
												WHERE
												  dbvente.vente.ID_Periode = dbvente.periode.ID_Periode AND
												  dbvente.vente.ID_Produit = dbvente.produit.ID_Produit AND
												  dbvente.vente.ID_Unite = dbvente.unites.ID_Unite AND
												  dbvente.vente.ID_Marche = 2 AND
												  dbvente.vente.ID_Famille = ' . $idf . ' ' . '
												ORDER BY
												  dbvente.periode.An DESC');
							
							?>
						
							<table border="2" width="100%" cellpadding="3">
								<?php
											
									while ($donnees = $reponse->fetch())
									{
										if($annee != $donnees['An']){
											echo '<tr>';
												echo '<th colspan="6">' . $donnees['An']. '</th>';
												echo '<tr>';
													echo '<th> Produit </th>';
													echo '<th> Unité </th>';
													echo '<th>Volume</th>';
													echo '<th>Prix Moyen</th>';
													echo '<th>Chiffre affaire devise</th>';
													echo '<th>Chiffre affaire dinars</th>';	
												echo '</tr>';	
											echo '</tr>';
										}
										
										echo '<tr><td>' . htmlspecialchars($donnees['Nom_Produit']) . '</td>';
											echo '<td>' . $donnees['Nom_Unite']. '</td>';	
											echo '<td>' . $donnees['Volume']. '</td>';
											if ($donnees['Prix']!=0){
												echo '<td>' . $donnees['Prix']. '</td>';}else{echo '<td>ND</td>';}
											if ($donnees['CA']!=0){
												echo '<td>' . $donnees['CA']. '</td>';}else{echo '<td>ND</td>';}
											if ($donnees['CA_Dinars']!=0){
												echo '<td>' . $donnees['CA_Dinars']. '</td>';}else{echo '<td>ND</td>';}
											$annee = $donnees['An'];
									}
									
								?>
							</table>
							
							<?php
						}
					}
				}
			}			
		}
	}
}
?>

Re: Tableau croisé dynamique

par master2011 » 29 août 2012, 13:52

Salut,

Je ne cherche pas qu'à afficher des colonnes ou pas, en fait c une solution brouillon de dépannage.

En fait, j'ai pas bien compris les idées proposées, alors j'ai fait cette altervative pour faire taire les gueuls des chefs.

Je voudrais sérieusement construire un tableau dynamique, mais dans vos réponses, j'ai déduit que mon besoin n'est pas claire alors j'ai bidouyé ce code.

Dans quel jointure y a erreur :?:
Pour le code pas claire je fais un post avec les balises php y a pas de soucis :!:
<?php
	try	{
		$bdd = new PDO('mysql:host=localhost;dbname=dbvente', 'root', 'mysql');
	}
	catch(Exception $e){
		die('Erreur : '.$e->getMessage());
	}
	
	$idf = isset($_POST['famille'])      ? $_POST['famille']      :null; //identifiant famille
	$idp = isset($_POST['produits'])     ? $_POST['produits']     :null; //identifiant produit
	$ids = isset($_POST['sousproduits']) ? $_POST['sousproduits'] :null; //identifiant sous produit	
	$idd = isset($_POST['spdetail'])     ? $_POST['spdetail']     :null; //identifiant sous produit	détail
	
	$idb = isset($_POST['du'])           ? $_POST['du']           :null; //identifiant date début (begin)
	$ide = isset($_POST['au'])           ? $_POST['au']           :null; //identifiant date fin (end)
	
	$vl = (isset($_POST['vl']))          ?$_POST['vl']            :null; //case à cocher pour la colonne des volumes
	$pm = (isset($_POST['pm']))          ?$_POST['pm']            :null; //case à cocher pour la colonne des prix moyens
	$cd = (isset($_POST['cd']))          ?$_POST['cd']            :null; //case à cocher pour la colonne des chiffres des affaires en devise
	$cl = (isset($_POST['cl']))          ?$_POST['cl']            :null; //case à cocher pour la colonne des chiffres des affaires en monnaie locale
?>

<form id="chgdetail" action="<?php echo($_SERVER['PHP_SELF']); ?>" method="post">
  <fieldset id="t0">
 
  <fieldset id="t2">
    <legend> Famille de produit </legend><br/>
	
    <label for="famille">Famille : </label> 
    <select name="famille" id="famille" tabindex="1" onchange="document.forms['chgdetail'].submit();"> <br/>
		<option value="-1">Toutes les familles</option>
		<?php	
			
			/*-----------------------------Famille de produit--------------------------------*/
		
			$reponse = $bdd->query('SELECT famille_produit.ID_Famille, famille_produit.Nom_Famille FROM famille_produit');
			
			$code_famille=array();
			$famille=array();
			
			$nb_famille = 0;
			
			if($reponse != false){
			
				while($ligne = $reponse->fetch(PDO::FETCH_ASSOC)){
					array_push($code_famille, $ligne['ID_Famille']);
					array_push($famille, $ligne['Nom_Famille']);
					$nb_famille++;
				}
			}
			
			for($i=0; $i<$nb_famille; $i++){
			?>
			
				<option value="<?php echo($code_famille[$i]); ?>"<?php echo((isset($idf) && $idf == $code_famille[$i])?" selected=\"selected\"":null); ?>><?php echo($famille[$i]); ?></option>
				
			<?php
			
			//$reponse->closeCursor();	
		}
		?>
	</select>    
    <p tabindex="2"/>
  </fieldset>
  
  <fieldset id="t3">
    <legend> Produits et Détails </legend><br/>
	
    <label for="produits">Produits : </label>
    <select name="produits" id="produits" tabindex="20" onchange="document.forms['chgdetail'].submit();"><br/>
		<option value="-1">Tous les produits</option>
		<?php
			
			/*-----------------------------------------Les produits -----------------------------------------*/
			
			$reponse = $bdd->query('SELECT produit.ID_Produit, produit.Nom_Produit
								FROM
								  produit
								WHERE
								  produit.ID_Famille = '.$idf.'');			
			
			$code_produit=array();
			$produit=array();
			
			$nb_produits = 0;
		
			if($reponse != false){
			
				while($ligne = $reponse->fetch(PDO::FETCH_ASSOC)){
					array_push($code_produit, $ligne['ID_Produit']);
					array_push($produit, $ligne['Nom_Produit']);
					$nb_produits++;
				}
			}			
			
			for($i=0; $i<$nb_produits; $i++){
			?>
			
				<option value="<?php echo($code_produit[$i]); ?>"<?php echo((isset($idp) && $idp == $code_produit[$i])?" selected=\"selected\"":null); ?>><?php echo($produit[$i]); ?></option>
				
			<?php
			
			$reponse->closeCursor();	
			}
		?>
	</select></br>
	
	<br/><label for="sousproduits">Sous produits : </label> 
		<select name="sousproduits" id="sousproduits" tabindex="21" onchange="document.forms['chgdetail'].submit();"><br/>
			<option value="-1">Tous les sous-produits</option>
			<?php
					
				/*-------------------------------------------------- Les sous produits --------------------------------*/
				
				if(isset($idp) && $idp!=-1){
					$reponse = $bdd->query('SELECT ID_Sous_Produit, Nom_Sous_Produit FROM sous_produit WHERE ID_Produit = ' . $idp .' '. 'ORDER BY ID_Sous_Produit');
						
					$nsp = 0;
							
					$code_sousproduit = array();
					$nom_sousproduit = array();
							
					while($ligne_sousproduit = $reponse->fetch(PDO::FETCH_ASSOC)){
						array_push($code_sousproduit, $ligne_sousproduit['ID_Sous_Produit']);
						array_push($nom_sousproduit, $ligne_sousproduit['Nom_Sous_Produit']);
						$nsp++;
					}				
					
					for($d=0; $d<$nsp; $d++){
					?>
				
						<option value="<?php echo($code_sousproduit[$d]); ?>"<?php echo((isset($ids) && $ids == $code_sousproduit[$d])?" selected=\"selected\"":null); ?>><?php echo($nom_sousproduit[$d]); ?></option>
					
					<?php
				
					$reponse->closeCursor();	
					}
				}	
			
			?>
		</select><br/>			
    
	<br/><label for="spdetail">Détail Sous produits : </label> 
		<select name="spdetail" id="spdetail" tabindex="22" onchange="document.forms['chgdetail'].submit();"><br/>
			<option value="-1">Détail des sous-produits</option>
			
			<?php
			
				/*----------------------------------------- Détail des sous produits ---------------------------------------*/
			
				if(isset($ids) && $ids!=-1){
					$reponse = $bdd->query('SELECT sous_produit_detail.ID_Sous_Produit_Detail
								   , sous_produit_detail.Nom_Sous_Produit_Detail
								FROM
								  sous_produit_detail
								WHERE
								  sous_produit_detail.ID_Sous_Produit = '. $ids .' '.'
								ORDER BY
								  sous_produit_detail.ID_Sous_Produit_Detail');
					
					$nspd = 0;
						
					$code_sousproduitdetail = array();
					$nom_sousproduitdetail = array();
						
					while($ligne_sousproduitdetail = $reponse->fetch(PDO::FETCH_ASSOC)){
						array_push($code_sousproduitdetail, $ligne_sousproduitdetail['ID_Sous_Produit_Detail']);
						array_push($nom_sousproduitdetail, $ligne_sousproduitdetail['Nom_Sous_Produit_Detail']);
						$nspd++;
					}
					
					if($nspd !=0) {		
							
						for($j=0; $j<$nspd; $j++){
					?>
							<option value="<?php echo($code_sousproduitdetail[$j]); ?>"<?php echo((isset($idd) && $idd == $code_sousproduitdetail[$j])?" selected=\"selected\"":null); ?>><?php echo($nom_sousproduitdetail[$j]); ?></option>
								
					<?php
						}
						$reponse->closeCursor();				
					}
			}
			?>
			
		</select>
	<p tabindex="23"/>	
  </fieldset>
  
  <!--------------------------------------- Critères de selection des périodes ----------------------------------------------->
  
  <fieldset id="t4">
    <legend>Période</legend><br/>
	
	<label for="du">du : </label>
    <select name="du" id="du" tabindex="35">
		<option value="-1">----</option>
		<?php

			$reponse = $bdd->query('SELECT DISTINCT periode.ID_Periode
								   , periode.An
								FROM
								  periode
								GROUP BY
								  periode.An
								ORDER BY
								  periode.An');
			
			$npd = 0;
						
			$code_periodedebut = array();
			$nom_periodedebut = array();
			
			while($ligne_periodedebut = $reponse->fetch(PDO::FETCH_ASSOC)){
				array_push($code_periodedebut, $ligne_periodedebut['ID_Periode']);
				array_push($nom_periodedebut, $ligne_periodedebut['An']);
				$npd++;
			}
					
					if($npd !=0) {		
							
						for($j=0; $j<$npd; $j++){
					?>
							<option value="<?php echo($code_periodedebut[$j]); ?>"<?php echo((isset($idb) && $idb == $code_periodedebut[$j])?" selected=\"selected\"":null); ?>><?php echo($nom_periodedebut[$j]); ?></option>
								
					<?php
						}
						$reponse->closeCursor();				
					}
		?>
    </select>
	
	<label for="au">au : </label>
	<select name="au" id="au" tabindex="36"><br/> 
		<option value="-1">----</option>
		<?php

			$reponse = $bdd->query('SELECT DISTINCT periode.ID_Periode
								   , periode.An
								FROM
								  periode
								GROUP BY
								  periode.An
								ORDER BY
								  periode.An');
			
			$npf = 0;
						
			$code_periodefin = array();
			$nom_periodefin = array();
			
			while($ligne_periodefin = $reponse->fetch(PDO::FETCH_ASSOC)){
				array_push($code_periodefin, $ligne_periodefin['ID_Periode']);
				array_push($nom_periodefin, $ligne_periodefin['An']);
				$npf++;
			}
					
					if($npf !=0) {		
							
						for($j=0; $j<$npf; $j++){
					?>
							<option value="<?php echo($code_periodefin[$j]); ?>"<?php echo((isset($ide) && $ide == $code_periodefin[$j])?" selected=\"selected\"":null); ?>><?php echo($nom_periodedebut[$j]); ?></option>
								
					<?php
						}
						$reponse->closeCursor();				
					}
		?>
    </select>
	<p tabindex="23"/>
  </fieldset>
  
  <!--------------------------------------- Critères de selection des unités de mesures -------------------------------------->
  
  <fieldset id="t5">
    <legend>Unités</legend><br/>
    
	<label for="unite">unités: </label>
	<select name="unite" id="unite" tabindex="45"><br/>
		<option value="-1">----</option>
		<?php

			$reponse = $bdd->query('SELECT DISTINCT unites.Nom_Unite FROM unites');

			while ($donnees = $reponse->fetch())
			{
				echo '<option value="choix">'.$donnees['Nom_Unite'].'</option>';
			}

			$reponse->closeCursor();
		?>
	</select>
	<p tabindex="23"/>
  </fieldset>
  
  <!--------------------------------------- Choix des colonnes à afficher ---------------------------------------------------->
  
  <p></p>
  <fieldset id="t6">
		<legend>Choix des informations à afficher</legend><br/>	
		
		<input type="checkbox" name="vl" value="on" checked="checked" /> Volume<br/><br/>
		<input type="checkbox" name="pm" value="on" checked="checked" /> Prix Moyen<br/><br/>
		<input type="checkbox" name="cd" value="on" checked="checked" /> Chiffre d'affaire en US$<br/><br/>
		<input type="checkbox" name="cl" value="on" checked="checked" /> Chiffre d'affaire en DA<br/><br/>

  </fieldset>
  
  <!--------------------------------------- Mise en forme finale du formulaire ----------------------------------------------->
  
  <p>
  <input id="recherche" name="recherche" type="submit" value="Rechercher" /> 
  <input id="reinitialiser" name="reinitialiser" type="reset" />
  </p>
  </fieldset>
  
  <fieldset id="t6">
    <legend>Résultat</legend><br/>
    <p>Affichage tabulaire du résultat de la recherche</p>
  </fieldset>
</form>

Re: Tableau croisé dynamique

par moogli » 29 août 2012, 13:04

- Merci d'utiliser la balise php plutot que code (pour avoir la colorisation synatxe et soulager ma souris et mon index ;) ).
- Au survol du code je t'invite à regarder la syntaxe d'une jointure :)
- A priori tu souhaite juste afficher ou non des colonnes, c'est beaucoup plus simple que prévu :)

ton code avec les if est juste,tu n'a pas le choix.

tu peux faire un poil mieux en utilisant un tableau mais le principe est la.

il te reste a créer dynamiquement la requête pour ne récupérer que les champs choisis (si tu utilise la notation tableau pour le nom des checkbox un simple implode peux suffire, bien sur après vérification des données).

Perso j'ai pas lu le code complet c'est trop dense et illisible sans colorisation de la syntaxe.

@+

Re: Tableau croisé dynamique

par master2011 » 29 août 2012, 12:42

Suite du post:

Schéma des tables:
CREATE TABLE IF NOT EXISTS periode
(
ID_Periode INT UNSIGNED NOT NULL AUTO_INCREMENT,
An YEAR NULL,
Mois TINYINT NULL,
Trimestre TINYINT NULL,
Semestre TINYINT NULL,
PRIMARY KEY (ID_Periode)
)ENGINE = INNODB;

CREATE TABLE IF NOT EXISTS famille_produit
(
ID_Famille TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,
Nom_Famille VARCHAR (30) NULL,
PRIMARY KEY (ID_Famille)
)ENGINE = INNODB;

CREATE TABLE IF NOT EXISTS produit
(
ID_Produit TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,
Nom_Produit VARCHAR (30) NULL,
ID_Famille TINYINT UNSIGNED NULL,
PRIMARY KEY (ID_Produit, ID_Famille),
CONSTRAINT FK_Produit_Famille FOREIGN KEY (ID_Famille) REFERENCES famille_produit (ID_Famille)
)ENGINE = INNODB;

CREATE TABLE IF NOT EXISTS sous_produit
(
ID_Sous_Produit SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
Nom_Sous_Produit VARCHAR (30) NULL,
ID_Famille TINYINT UNSIGNED NULL,
ID_Produit TINYINT UNSIGNED NULL,
PRIMARY KEY (ID_Sous_Produit, ID_Famille, ID_Produit),
CONSTRAINT FK_Famille_Sous_Produit FOREIGN KEY (ID_Famille) REFERENCES produit (ID_Famille),
CONSTRAINT FK_Produit_Sous_Produit FOREIGN KEY (ID_Produit) REFERENCES produit (ID_Produit)
)ENGINE = INNODB;

create table sous_produit_detail
(
ID_Sous_Produit_Detail SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
Nom_Sous_Produit_Detail VARCHAR (30) NULL,
ID_Famille TINYINT UNSIGNED NULL,
ID_Produit TINYINT UNSIGNED NULL,
ID_Sous_Produit SMALLINT UNSIGNED NULL,
PRIMARY KEY (ID_Sous_Produit_Detail, ID_Famille, ID_Produit, ID_Sous_Produit),
CONSTRAINT FK_Sous_Produit_Detail_Famille FOREIGN KEY (ID_Famille) REFERENCES sous_produit (ID_Famille),
CONSTRAINT FK_Sous_Produit_Detail_Produit FOREIGN KEY (ID_Produit) REFERENCES sous_produit (ID_Produit),
CONSTRAINT FK_Sous_Produit_Detail_Sous_Produit FOREIGN KEY (ID_Sous_Produit) REFERENCES sous_produit (ID_Sous_Produit)
)ENGINE = INNODB;

CREATE TABLE IF NOT EXISTS unites
(
ID_Unite TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,
Nom_Unite VARCHAR (30) NULL,
Commentaire VARCHAR (254) NULL,
ID_Produit TINYINT UNSIGNED NULL,
ID_Sous_Produit SMALLINT UNSIGNED NULL,
ID_Sous_Produit_Detail SMALLINT UNSIGNED NULL,
PRIMARY KEY (ID_Unite),
CONSTRAINT FK_Unite_Produit FOREIGN KEY (ID_Produit) REFERENCES Produit (ID_Produit),
CONSTRAINT FK_Unite_Sous_Produit FOREIGN KEY (ID_Sous_Produit) REFERENCES Sous_Produit (ID_Sous_Produit),
CONSTRAINT FK_Unite_Sous_Produit_Detail FOREIGN KEY (ID_Sous_Produit_Detail) REFERENCES sous_produit_detail (ID_Sous_Produit_Detail)
)ENGINE = INNODB;

CREATE TABLE IF NOT EXISTS vente
(
ID_Vente BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
Volume FLOAT NULL,
Prix FLOAT NULL,
CA FLOAT NULL,
CA_Dinars FLOAT NULL,
ID_Famille TINYINT UNSIGNED NULL,
ID_Produit TINYINT UNSIGNED NULL,
ID_Periode INT UNSIGNED NULL,
ID_Unite TINYINT UNSIGNED NULL,
ID_Marche TINYINT UNSIGNED NULL,
PRIMARY KEY (ID_Vente),
CONSTRAINT FK_Vente_Famille FOREIGN KEY (ID_Famille) REFERENCES produit (ID_Famille),
CONSTRAINT FK_Vente_Produit FOREIGN KEY (ID_Produit) REFERENCES produit (ID_Produit),
CONSTRAINT FK_Vente_Periode FOREIGN KEY (ID_Periode) REFERENCES periode (ID_Periode),
CONSTRAINT FK_Vente_Unite FOREIGN KEY (ID_Unite) REFERENCES unites (ID_Unite),
Constraint FK_Vente_Marche FOREIGN KEY (ID_Marche) REFERENCES marche (ID_Marche)
)ENGINE = INNODB;

CREATE TABLE IF NOT EXISTS vente_detail
(
ID_Vente_detail BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
Volume FLOAT NULL,
Prix FLOAT NULL,
CA FLOAT NULL,
CA_Dinars FLOAT NULL,
ID_Sous_Produit SMALLINT UNSIGNED NULL,
ID_Periode INT UNSIGNED NULL,
ID_Unite TINYINT UNSIGNED NULL,
ID_Marche TINYINT UNSIGNED NULL,
PRIMARY KEY (ID_Vente_Detail),
CONSTRAINT FK_Vente_Sous_Produit FOREIGN KEY (ID_Sous_Produit) REFERENCES sous_produit (ID_Sous_Produit),
CONSTRAINT FK_Vente_Detail_Periode FOREIGN KEY (ID_Periode) REFERENCES periode (ID_Periode),
CONSTRAINT FK_Vente_Detail_Unite FOREIGN KEY (ID_Unite) REFERENCES unites (ID_Unite),
Constraint FK_Vente_Detail_Marche FOREIGN KEY (ID_Marche) REFERENCES marche (ID_Marche)
)ENGINE = INNODB;

CREATE TABLE IF NOT EXISTS vente_sous_detail
(
ID_Vente_Sous_Detail BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
Volume FLOAT NULL,
Prix FLOAT NULL,
CA FLOAT NULL,
CA_Dinars FLOAT NULL,
ID_Sous_Produit_Detail SMALLINT UNSIGNED NULL,
ID_Periode INT UNSIGNED NULL,
ID_Unite TINYINT UNSIGNED NULL,
ID_Marche TINYINT UNSIGNED NULL,
PRIMARY KEY (ID_Vente_Sous_Detail),
CONSTRAINT FK_Vente_Sous_Produit_Detail FOREIGN KEY (ID_Sous_Produit_Detail) REFERENCES sous_produit_detail (ID_Sous_Produit_Detail),
CONSTRAINT FK_Vente_Sous_Detail_Periode FOREIGN KEY (ID_Periode) REFERENCES periode (ID_Periode),
CONSTRAINT FK_Vente_Sous_Detail_Unite FOREIGN KEY (ID_Unite) REFERENCES unites (ID_Unite),
Constraint FK_Vente_Sous_Detail_Marche FOREIGN KEY (ID_Marche) REFERENCES marche (ID_Marche)
)ENGINE = INNODB;

Re: Tableau croisé dynamique

par master2011 » 29 août 2012, 12:40

Suite du post:

Code : Tout sélectionner

<!----------------------------------------- Recherche des données ---------------------------------------------> <?php $annee = 1900; //Vérification de la période choisie if($idb>0 && $ide>0) { //Vérifier que les périodes sont cohérentes if($ide < $idb) { /*Afficher un message d'erreur Maintenir le focus sur le fieldset période*/ } //SINON else { //La période choisite est comprise entre date début et une date fin if($idd>0) { $reponse = $bdd->query('SELECT dbvente.periode.An, dbvente.sous_produit_detail.Nom_Sous_Produit_Detail, dbvente.unites.Nom_Unite, dbvente.vente_sous_detail.Volume, dbvente.vente_sous_detail.Prix, dbvente.vente_sous_detail.CA, dbvente.vente_sous_detail.CA_Dinars FROM dbvente.vente_sous_detail, dbvente.sous_produit_detail, dbvente.periode, dbvente.produit, dbvente.sous_produit, dbvente.unites, dbvente.famille_produit WHERE dbvente.famille_produit.ID_Famille = ' . $idf . ' AND dbvente.produit.ID_Produit = ' . $idp . ' AND dbvente.sous_produit.ID_Sous_Produit = ' . $ids . ' AND dbvente.vente_sous_detail.ID_Marche = 2 AND dbvente.vente_sous_detail.ID_Periode BETWEEN ' .$idb . ' AND ' . $ide . ' AND dbvente.sous_produit_detail.ID_Sous_Produit_Detail = ' . $idd . ' AND dbvente.vente_sous_detail.ID_Periode = dbvente.periode.ID_Periode AND dbvente.vente_sous_detail.ID_Sous_Produit_Detail = dbvente.sous_produit_detail.ID_Sous_Produit_Detail AND dbvente.sous_produit_detail.ID_Sous_Produit = dbvente.sous_produit.ID_Sous_Produit AND dbvente.sous_produit.ID_Produit = dbvente.produit.ID_Produit AND dbvente.vente_sous_detail.ID_Unite = dbvente.unites.ID_Unite AND dbvente.famille_produit.ID_Famille = dbvente.produit.ID_Famille ORDER BY dbvente.periode.An DESC'); ?> <table border="2" width="100%" cellpadding="3"> <?php //if(!empty($vl) || !empty($pm) || !empty($cd) || !empty($cl)){ while ($donnees = $reponse->fetch()) { if($annee != $donnees['An']){ echo '<tr>'; echo '<th colspan="6">' . $donnees['An']. '</th>'; echo '<tr>'; echo '<th> Sous-Produits </th>'; echo '<th> Unité </th>'; //if(!empty($vl)) {echo '<th>Volume</th>';} //if(!empty($pm)) {echo '<th>Prix Moyen</th>';} if(!empty($cd)) //{echo '<th>Chiffre affaire devise</th>';} //if(!empty($cl)) {echo '<th>Chiffre affaire dinars</th>';} echo '</tr>'; echo '</tr>'; } echo '<tr><td>' . htmlspecialchars($donnees['Nom_Sous_Produit_Detail']) . '</td>'; echo '<td>' . $donnees['Nom_Unite']. '</td>'; echo '<td>' . $donnees['Volume']. '</td>'; if ($donnees['Prix']!=0){ echo '<td>' . $donnees['Prix']. '</td>';}else{echo '<td>ND</td>';} if ($donnees['CA']!=0){ echo '<td>' . $donnees['CA']. '</td>';}else{echo '<td>ND</td>';} if ($donnees['CA_Dinars']!=0){ echo '<td>' . $donnees['CA_Dinars']. '</td>';}else{echo '<td>ND</td>';} $annee = $donnees['An']; }//} ?> </table> <?php } //SINON else { if($ids>0) { /*afficher toutes les ventes réalisées du sous produit je manipule à ce niveau la table vente de sous produit et la table détail*/ $reponse = $bdd->query('SELECT dbvente.periode.An, dbvente.sous_produit_detail.Nom_Sous_Produit_Detail, dbvente.unites.Nom_Unite, dbvente.vente_sous_detail.Volume, dbvente.vente_sous_detail.Prix, dbvente.vente_sous_detail.CA, dbvente.vente_sous_detail.CA_Dinars FROM dbvente.vente_sous_detail, dbvente.sous_produit_detail, dbvente.periode, dbvente.produit, dbvente.sous_produit, dbvente.unites, dbvente.famille_produit WHERE dbvente.famille_produit.ID_Famille = ' . $idf . ' AND dbvente.produit.ID_Produit = ' . $idp . ' AND dbvente.sous_produit.ID_Sous_Produit = ' . $ids . ' AND dbvente.vente_sous_detail.ID_Periode BETWEEN ' . $idb . ' AND ' . $ide . ' AND dbvente.vente_sous_detail.ID_Marche = 2 AND dbvente.vente_sous_detail.ID_Periode = dbvente.periode.ID_Periode AND dbvente.vente_sous_detail.ID_Sous_Produit_Detail = dbvente.sous_produit_detail.ID_Sous_Produit_Detail AND dbvente.sous_produit_detail.ID_Sous_Produit = dbvente.sous_produit.ID_Sous_Produit AND dbvente.sous_produit.ID_Produit = dbvente.produit.ID_Produit AND dbvente.vente_sous_detail.ID_Unite = dbvente.unites.ID_Unite AND dbvente.famille_produit.ID_Famille = dbvente.produit.ID_Famille ORDER BY dbvente.periode.An DESC'); ?> <table border="2" width="100%" cellpadding="3"> <?php while ($donnees = $reponse->fetch()) { if($annee != $donnees['An']){ echo '<tr>'; echo '<th colspan="6">' . $donnees['An']. '</th>'; echo '<tr>'; echo '<th> Détail Sous-Produits </th>'; echo '<th> Unité </th>'; echo '<th>Volume</th>'; echo '<th>Prix Moyen</th>'; echo '<th>Chiffre affaire devise</th>'; echo '<th>Chiffre affaire dinars</th>'; echo '</tr>'; echo '</tr>'; } echo '<tr><td>' . htmlspecialchars($donnees['Nom_Sous_Produit_Detail']) . '</td>'; echo '<td>' . $donnees['Nom_Unite']. '</td>'; echo '<td>' . $donnees['Volume']. '</td>'; if ($donnees['Prix']!=0){ echo '<td>' . $donnees['Prix']. '</td>';}else{echo '<td>ND</td>';} if ($donnees['CA']!=0){ echo '<td>' . $donnees['CA']. '</td>';}else{echo '<td>ND</td>';} if ($donnees['CA_Dinars']!=0){ echo '<td>' . $donnees['CA_Dinars']. '</td>';}else{echo '<td>ND</td>';} $annee = $donnees['An']; } ?> </table> <?php } //SINON else { if($idp>0) { /*afficher toutes les ventes réalisées du produit je manipile à ce niveau la table vente globale et la table de vente de sous produit*/ $reponse = $bdd->query('SELECT dbvente.periode.An, dbvente.sous_produit.Nom_Sous_Produit, dbvente.unites.Nom_Unite, dbvente.vente_detail.Volume, dbvente.vente_detail.Prix, dbvente.vente_detail.CA, dbvente.vente_detail.CA_Dinars FROM dbvente.periode, dbvente.sous_produit, dbvente.vente_detail, dbvente.produit, dbvente.famille_produit, dbvente.unites WHERE dbvente.vente_detail.ID_Periode = dbvente.periode.ID_Periode AND dbvente.vente_detail.ID_Sous_Produit = dbvente.sous_produit.ID_Sous_Produit AND dbvente.sous_produit.ID_Produit = dbvente.produit.ID_Produit AND dbvente.produit.ID_Famille = dbvente.famille_produit.ID_Famille AND dbvente.vente_detail.ID_Unite = dbvente.unites.ID_Unite AND dbvente.vente_detail.ID_Marche = 2 AND dbvente.famille_produit.ID_Famille = ' . $idf . ' AND dbvente.sous_produit.ID_Produit = ' . $idp . ' AND dbvente.vente_detail.ID_Periode BETWEEN ' . $idb . ' AND ' . $ide . ' '.' ORDER BY dbvente.periode.An DESC'); ?> <table border="2" width="100%" cellpadding="3"> <?php while ($donnees = $reponse->fetch()) { if($annee != $donnees['An']){ echo '<tr>'; echo '<th colspan="6">' . $donnees['An']. '</th>'; echo '<tr>'; echo '<th> Sous-Produits </th>'; echo '<th> Unité </th>'; echo '<th>Volume</th>'; echo '<th>Prix Moyen</th>'; echo '<th>Chiffre affaire devise</th>'; echo '<th>Chiffre affaire dinars</th>'; echo '</tr>'; echo '</tr>'; } echo '<tr><td>' . htmlspecialchars($donnees['Nom_Sous_Produit']) . '</td>'; echo '<td>' . $donnees['Nom_Unite']. '</td>'; echo '<td>' . $donnees['Volume']. '</td>'; if ($donnees['Prix']!=0){ echo '<td>' . $donnees['Prix']. '</td>';}else{echo '<td>ND</td>';} if ($donnees['CA']!=0){ echo '<td>' . $donnees['CA']. '</td>';}else{echo '<td>ND</td>';} if ($donnees['CA_Dinars']!=0){ echo '<td>' . $donnees['CA_Dinars']. '</td>';}else{echo '<td>ND</td>';} $annee = $donnees['An']; } ?> </table> <?php } else { if($idf>0) { /*afficher toutes les ventes réalisées de la famille je manipile à ce niveau la table vente globale*/ $reponse = $bdd->query('SELECT dbvente.periode.An, dbvente.produit.Nom_Produit, dbvente.unites.Nom_Unite, dbvente.vente.Volume, dbvente.vente.Prix, dbvente.vente.CA, dbvente.vente.CA_Dinars FROM dbvente.periode, dbvente.produit, dbvente.vente, dbvente.unites WHERE dbvente.vente.ID_Periode = dbvente.periode.ID_Periode AND dbvente.vente.ID_Produit = dbvente.produit.ID_Produit AND dbvente.vente.ID_Unite = dbvente.unites.ID_Unite AND dbvente.vente.ID_Marche = 2 AND dbvente.vente.ID_Famille = ' . $idf . ' ' . 'AND dbvente.vente.ID_Periode BETWEEN ' . $idb . ' AND '. $ide .' '.' ORDER BY dbvente.periode.An DESC'); ?> <table border="2" width="100%" cellpadding="3"> <?php while ($donnees = $reponse->fetch()) { if($annee != $donnees['An']){ echo '<tr>'; echo '<th colspan="6">' . $donnees['An']. '</th>'; echo '<tr>'; echo '<th> Produit </th>'; echo '<th> Unité </th>'; echo '<th>Volume</th>'; echo '<th>Prix Moyen</th>'; echo '<th>Chiffre affaire devise</th>'; echo '<th>Chiffre affaire dinars</th>'; echo '</tr>'; echo '</tr>'; } echo '<tr><td>' . htmlspecialchars($donnees['Nom_Produit']) . '</td>'; echo '<td>' . $donnees['Nom_Unite']. '</td>'; echo '<td>' . $donnees['Volume']. '</td>'; if ($donnees['Prix']!=0){ echo '<td>' . $donnees['Prix']. '</td>';}else{echo '<td>ND</td>';} if ($donnees['CA']!=0){ echo '<td>' . $donnees['CA']. '</td>';}else{echo '<td>ND</td>';} if ($donnees['CA_Dinars']!=0){ echo '<td>' . $donnees['CA_Dinars']. '</td>';}else{echo '<td>ND</td>';} $annee = $donnees['An']; } ?> </table> <?php } } } } } } /*Sinon Vérifier les intervales choisis*/ else { //La période choisie correspond à depuis une date début jusqu'à présent if($idb>0 && $ide<=0) { if($idd>0) { $reponse = $bdd->query('SELECT dbvente.periode.An, dbvente.sous_produit_detail.Nom_Sous_Produit_Detail, dbvente.unites.Nom_Unite, dbvente.vente_sous_detail.Volume, dbvente.vente_sous_detail.Prix, dbvente.vente_sous_detail.CA, dbvente.vente_sous_detail.CA_Dinars FROM dbvente.vente_sous_detail, dbvente.sous_produit_detail, dbvente.periode, dbvente.produit, dbvente.sous_produit, dbvente.unites, dbvente.famille_produit WHERE dbvente.famille_produit.ID_Famille = ' . $idf . ' AND dbvente.produit.ID_Produit = ' . $idp . ' AND dbvente.sous_produit.ID_Sous_Produit = ' . $ids . ' AND dbvente.vente_sous_detail.ID_Marche = 2 AND dbvente.vente_sous_detail.ID_Periode >= ' .$idb . ' ' . ' dbvente.sous_produit_detail.ID_Sous_Produit_Detail = ' . $idd . ' AND dbvente.vente_sous_detail.ID_Periode = dbvente.periode.ID_Periode AND dbvente.vente_sous_detail.ID_Sous_Produit_Detail = dbvente.sous_produit_detail.ID_Sous_Produit_Detail AND dbvente.sous_produit_detail.ID_Sous_Produit = dbvente.sous_produit.ID_Sous_Produit AND dbvente.sous_produit.ID_Produit = dbvente.produit.ID_Produit AND dbvente.vente_sous_detail.ID_Unite = dbvente.unites.ID_Unite AND dbvente.famille_produit.ID_Famille = dbvente.produit.ID_Famille ORDER BY dbvente.periode.An DESC'); ?> <table border="2" width="100%" cellpadding="3"> <?php while ($donnees = $reponse->fetch()) { if($annee != $donnees['An']){ echo '<tr>'; echo '<th colspan="6">' . $donnees['An']. '</th>'; echo '<tr>'; echo '<th> Sous-Produits </th>'; echo '<th> Unité </th>'; echo '<th>Volume</th>'; echo '<th>Prix Moyen</th>'; echo '<th>Chiffre affaire devise</th>'; echo '<th>Chiffre affaire dinars</th>'; echo '</tr>'; echo '</tr>'; } echo '<tr><td>' . htmlspecialchars($donnees['Nom_Sous_Produit_Detail']) . '</td>'; echo '<td>' . $donnees['Nom_Unite']. '</td>'; echo '<td>' . $donnees['Volume']. '</td>'; if ($donnees['Prix']!=0){ echo '<td>' . $donnees['Prix']. '</td>';}else{echo '<td>ND</td>';} if ($donnees['CA']!=0){ echo '<td>' . $donnees['CA']. '</td>';}else{echo '<td>ND</td>';} if ($donnees['CA_Dinars']!=0){ echo '<td>' . $donnees['CA_Dinars']. '</td>';}else{echo '<td>ND</td>';} $annee = $donnees['An']; } ?> </table> <?php } //SINON else { //SI produit selectionné ALORS if($ids>0) { /*afficher toutes les ventes réalisées du sous produit je manipule à ce niveau la table vente de sous produit et la table détail*/ $reponse = $bdd->query('SELECT dbvente.periode.An, dbvente.sous_produit_detail.Nom_Sous_Produit_Detail, dbvente.unites.Nom_Unite, dbvente.vente_sous_detail.Volume, dbvente.vente_sous_detail.Prix, dbvente.vente_sous_detail.CA, dbvente.vente_sous_detail.CA_Dinars FROM dbvente.vente_sous_detail, dbvente.sous_produit_detail, dbvente.periode, dbvente.produit, dbvente.sous_produit, dbvente.unites, dbvente.famille_produit WHERE dbvente.famille_produit.ID_Famille = ' . $idf . ' AND dbvente.produit.ID_Produit = ' . $idp . ' AND dbvente.sous_produit.ID_Sous_Produit = ' . $ids . ' AND dbvente.vente_sous_detail.ID_Periode >= ' . $idb . ' ' . ' dbvente.vente_sous_detail.ID_Marche = 2 AND dbvente.vente_sous_detail.ID_Periode = dbvente.periode.ID_Periode AND dbvente.vente_sous_detail.ID_Sous_Produit_Detail = dbvente.sous_produit_detail.ID_Sous_Produit_Detail AND dbvente.sous_produit_detail.ID_Sous_Produit = dbvente.sous_produit.ID_Sous_Produit AND dbvente.sous_produit.ID_Produit = dbvente.produit.ID_Produit AND dbvente.vente_sous_detail.ID_Unite = dbvente.unites.ID_Unite AND dbvente.famille_produit.ID_Famille = dbvente.produit.ID_Famille ORDER BY dbvente.periode.An DESC'); ?> <table border="2" width="100%" cellpadding="3"> <?php while ($donnees = $reponse->fetch()) { if($annee != $donnees['An']){ echo '<tr>'; echo '<th colspan="6">' . $donnees['An']. '</th>'; echo '<tr>'; echo '<th> Sous-Produits </th>'; echo '<th> Unité </th>'; echo '<th>Volume</th>'; echo '<th>Prix Moyen</th>'; echo '<th>Chiffre affaire devise</th>'; echo '<th>Chiffre affaire dinars</th>'; echo '</tr>'; echo '</tr>'; } echo '<tr><td>' . htmlspecialchars($donnees['Nom_Sous_Produit_Detail']) . '</td>'; echo '<td>' . $donnees['Nom_Unite']. '</td>'; echo '<td>' . $donnees['Volume']. '</td>'; if ($donnees['Prix']!=0){ echo '<td>' . $donnees['Prix']. '</td>';}else{echo '<td>ND</td>';} if ($donnees['CA']!=0){ echo '<td>' . $donnees['CA']. '</td>';}else{echo '<td>ND</td>';} if ($donnees['CA_Dinars']!=0){ echo '<td>' . $donnees['CA_Dinars']. '</td>';}else{echo '<td>ND</td>';} $annee = $donnees['An']; } ?> </table> <?php } //SINON else { //SI sous produit selectionné ALORS if($idp>0) { /*afficher toutes les ventes réalisées du produit je manipile à ce niveau la table vente globale et la table de vente de sous produit*/ $reponse = $bdd->query('SELECT dbvente.periode.An, dbvente.sous_produit.Nom_Sous_Produit, dbvente.unites.Nom_Unite, dbvente.vente_detail.Volume, dbvente.vente_detail.Prix, dbvente.vente_detail.CA, dbvente.vente_detail.CA_Dinars FROM dbvente.periode, dbvente.sous_produit, dbvente.vente_detail, dbvente.produit, dbvente.famille_produit, dbvente.unites WHERE dbvente.vente_detail.ID_Periode = dbvente.periode.ID_Periode AND dbvente.vente_detail.ID_Sous_Produit = dbvente.sous_produit.ID_Sous_Produit AND dbvente.sous_produit.ID_Produit = dbvente.produit.ID_Produit AND dbvente.produit.ID_Famille = dbvente.famille_produit.ID_Famille AND dbvente.vente_detail.ID_Unite = dbvente.unites.ID_Unite AND dbvente.vente_detail.ID_Marche = 2 AND dbvente.famille_produit.ID_Famille = ' . $idf . ' AND dbvente.sous_produit.ID_Produit = ' . $idp . ' AND dbvente.vente_detail.ID_Periode >= ' . $idb . ' ' .' ORDER BY dbvente.periode.An DESC'); ?> <table border="2" width="100%" cellpadding="3"> <?php while ($donnees = $reponse->fetch()) { if($annee != $donnees['An']){ echo '<tr>'; echo '<th colspan="6">' . $donnees['An']. '</th>'; echo '<tr>'; echo '<th> Sous-Produits </th>'; echo '<th> Unité </th>'; echo '<th>Volume</th>'; echo '<th>Prix Moyen</th>'; echo '<th>Chiffre affaire devise</th>'; echo '<th>Chiffre affaire dinars</th>'; echo '</tr>'; echo '</tr>'; } echo '<tr><td>' . htmlspecialchars($donnees['Nom_Sous_Produit']) . '</td>'; echo '<td>' . $donnees['Nom_Unite']. '</td>'; echo '<td>' . $donnees['Volume']. '</td>'; if ($donnees['Prix']!=0){ echo '<td>' . $donnees['Prix']. '</td>';}else{echo '<td>ND</td>';} if ($donnees['CA']!=0){ echo '<td>' . $donnees['CA']. '</td>';}else{echo '<td>ND</td>';} if ($donnees['CA_Dinars']!=0){ echo '<td>' . $donnees['CA_Dinars']. '</td>';}else{echo '<td>ND</td>';} $annee = $donnees['An']; } ?> </table> <?php } else { if($idf>0) { /*afficher toutes les ventes réalisées de la famille je manipile à ce niveau la table vente globale*/ $reponse = $bdd->query('SELECT dbvente.periode.An, dbvente.produit.Nom_Produit, dbvente.unites.Nom_Unite, dbvente.vente.Volume, dbvente.vente.Prix, dbvente.vente.CA, dbvente.vente.CA_Dinars FROM dbvente.periode, dbvente.produit, dbvente.vente, dbvente.unites WHERE dbvente.vente.ID_Periode = dbvente.periode.ID_Periode AND dbvente.vente.ID_Produit = dbvente.produit.ID_Produit AND dbvente.vente.ID_Unite = dbvente.unites.ID_Unite AND dbvente.vente.ID_Marche = 2 AND dbvente.vente.ID_Famille = ' . $idf . ' ' . 'AND dbvente.vente.ID_Periode >= ' . $idb . ' '.' ORDER BY dbvente.periode.An DESC'); ?> <table border="2" width="100%" cellpadding="3"> <?php while ($donnees = $reponse->fetch()) { if($annee != $donnees['An']){ echo '<tr>'; echo '<th colspan="6">' . $donnees['An']. '</th>'; echo '<tr>'; echo '<th> Produit </th>'; echo '<th> Unité </th>'; echo '<th>Volume</th>'; echo '<th>Prix Moyen</th>'; echo '<th>Chiffre affaire devise</th>'; echo '<th>Chiffre affaire dinars</th>'; echo '</tr>'; echo '</tr>'; } echo '<tr><td>' . htmlspecialchars($donnees['Nom_Produit']) . '</td>'; echo '<td>' . $donnees['Nom_Unite']. '</td>'; echo '<td>' . $donnees['Volume']. '</td>'; if ($donnees['Prix']!=0){ echo '<td>' . $donnees['Prix']. '</td>';}else{echo '<td>ND</td>';} if ($donnees['CA']!=0){ echo '<td>' . $donnees['CA']. '</td>';}else{echo '<td>ND</td>';} if ($donnees['CA_Dinars']!=0){ echo '<td>' . $donnees['CA_Dinars']. '</td>';}else{echo '<td>ND</td>';} $annee = $donnees['An']; } ?> </table> <?php } } } } } else { if($idb<=0 && $ide>0) { //La période choisie correspond à toutes les dates jusqu'à une date précise if($idd>0) { $reponse = $bdd->query('SELECT dbvente.periode.An, dbvente.sous_produit_detail.Nom_Sous_Produit_Detail, dbvente.unites.Nom_Unite, dbvente.vente_sous_detail.Volume, dbvente.vente_sous_detail.Prix, dbvente.vente_sous_detail.CA, dbvente.vente_sous_detail.CA_Dinars FROM dbvente.vente_sous_detail, dbvente.sous_produit_detail, dbvente.periode, dbvente.produit, dbvente.sous_produit, dbvente.unites, dbvente.famille_produit WHERE dbvente.famille_produit.ID_Famille = ' . $idf . ' AND dbvente.produit.ID_Produit = ' . $idp . ' AND dbvente.sous_produit.ID_Sous_Produit = ' . $ids . ' AND dbvente.vente_sous_detail.ID_Marche = 2 AND dbvente.vente_sous_detail.ID_Periode <= ' .$ide . ' ' . ' dbvente.sous_produit_detail.ID_Sous_Produit_Detail = ' . $idd . ' AND dbvente.vente_sous_detail.ID_Periode = dbvente.periode.ID_Periode AND dbvente.vente_sous_detail.ID_Sous_Produit_Detail = dbvente.sous_produit_detail.ID_Sous_Produit_Detail AND dbvente.sous_produit_detail.ID_Sous_Produit = dbvente.sous_produit.ID_Sous_Produit AND dbvente.sous_produit.ID_Produit = dbvente.produit.ID_Produit AND dbvente.vente_sous_detail.ID_Unite = dbvente.unites.ID_Unite AND dbvente.famille_produit.ID_Famille = dbvente.produit.ID_Famille ORDER BY dbvente.periode.An DESC'); ?> <table border="2" width="100%" cellpadding="3"> <?php while ($donnees = $reponse->fetch()) { if($annee != $donnees['An']){ echo '<tr>'; echo '<th colspan="6">' . $donnees['An']. '</th>'; echo '<tr>'; echo '<th> Sous-Produits </th>'; echo '<th> Unité </th>'; echo '<th>Volume</th>'; echo '<th>Prix Moyen</th>'; echo '<th>Chiffre affaire devise</th>'; echo '<th>Chiffre affaire dinars</th>'; echo '</tr>'; echo '</tr>'; } echo '<tr><td>' . htmlspecialchars($donnees['Nom_Sous_Produit_Detail']) . '</td>'; echo '<td>' . $donnees['Nom_Unite']. '</td>'; echo '<td>' . $donnees['Volume']. '</td>'; if ($donnees['Prix']!=0){ echo '<td>' . $donnees['Prix']. '</td>';}else{echo '<td>ND</td>';} if ($donnees['CA']!=0){ echo '<td>' . $donnees['CA']. '</td>';}else{echo '<td>ND</td>';} if ($donnees['CA_Dinars']!=0){ echo '<td>' . $donnees['CA_Dinars']. '</td>';}else{echo '<td>ND</td>';} $annee = $donnees['An']; } ?> </table> <?php } //SINON else { //SI produit selectionné ALORS if($ids>0) { /*afficher toutes les ventes réalisées du sous produit je manipule à ce niveau la table vente de sous produit et la table détail*/ $reponse = $bdd->query('SELECT dbvente.periode.An, dbvente.sous_produit_detail.Nom_Sous_Produit_Detail, dbvente.unites.Nom_Unite, dbvente.vente_sous_detail.Volume, dbvente.vente_sous_detail.Prix, dbvente.vente_sous_detail.CA, dbvente.vente_sous_detail.CA_Dinars FROM dbvente.vente_sous_detail, dbvente.sous_produit_detail, dbvente.periode, dbvente.produit, dbvente.sous_produit, dbvente.unites, dbvente.famille_produit WHERE dbvente.famille_produit.ID_Famille = ' . $idf . ' AND dbvente.produit.ID_Produit = ' . $idp . ' AND dbvente.sous_produit.ID_Sous_Produit = ' . $ids . ' AND dbvente.vente_sous_detail.ID_Periode <= ' . $ide . ' ' . ' dbvente.vente_sous_detail.ID_Marche = 2 AND dbvente.vente_sous_detail.ID_Periode = dbvente.periode.ID_Periode AND dbvente.vente_sous_detail.ID_Sous_Produit_Detail = dbvente.sous_produit_detail.ID_Sous_Produit_Detail AND dbvente.sous_produit_detail.ID_Sous_Produit = dbvente.sous_produit.ID_Sous_Produit AND dbvente.sous_produit.ID_Produit = dbvente.produit.ID_Produit AND dbvente.vente_sous_detail.ID_Unite = dbvente.unites.ID_Unite AND dbvente.famille_produit.ID_Famille = dbvente.produit.ID_Famille ORDER BY dbvente.periode.An DESC'); ?> <table border="2" width="100%" cellpadding="3"> <?php while ($donnees = $reponse->fetch()) { if($annee != $donnees['An']){ echo '<tr>'; echo '<th colspan="6">' . $donnees['An']. '</th>'; echo '<tr>'; echo '<th> Sous-Produits </th>'; echo '<th> Unité </th>'; echo '<th>Volume</th>'; echo '<th>Prix Moyen</th>'; echo '<th>Chiffre affaire devise</th>'; echo '<th>Chiffre affaire dinars</th>'; echo '</tr>'; echo '</tr>'; } echo '<tr><td>' . htmlspecialchars($donnees['Nom_Sous_Produit_Detail']) . '</td>'; echo '<td>' . $donnees['Nom_Unite']. '</td>'; echo '<td>' . $donnees['Volume']. '</td>'; if ($donnees['Prix']!=0){ echo '<td>' . $donnees['Prix']. '</td>';}else{echo '<td>ND</td>';} if ($donnees['CA']!=0){ echo '<td>' . $donnees['CA']. '</td>';}else{echo '<td>ND</td>';} if ($donnees['CA_Dinars']!=0){ echo '<td>' . $donnees['CA_Dinars']. '</td>';}else{echo '<td>ND</td>';} $annee = $donnees['An']; } ?> </table> <?php } //SINON else { //SI sous produit selectionné ALORS if($idp>0) { /*afficher toutes les ventes réalisées du produit je manipile à ce niveau la table vente globale et la table de vente de sous produit*/ $reponse = $bdd->query('SELECT dbvente.periode.An, dbvente.sous_produit.Nom_Sous_Produit, dbvente.unites.Nom_Unite, dbvente.vente_detail.Volume, dbvente.vente_detail.Prix, dbvente.vente_detail.CA, dbvente.vente_detail.CA_Dinars FROM dbvente.periode, dbvente.sous_produit, dbvente.vente_detail, dbvente.produit, dbvente.famille_produit, dbvente.unites WHERE dbvente.vente_detail.ID_Periode = dbvente.periode.ID_Periode AND dbvente.vente_detail.ID_Sous_Produit = dbvente.sous_produit.ID_Sous_Produit AND dbvente.sous_produit.ID_Produit = dbvente.produit.ID_Produit AND dbvente.produit.ID_Famille = dbvente.famille_produit.ID_Famille AND dbvente.vente_detail.ID_Unite = dbvente.unites.ID_Unite AND dbvente.vente_detail.ID_Marche = 2 AND dbvente.famille_produit.ID_Famille = ' . $idf . ' AND dbvente.sous_produit.ID_Produit = ' . $idp . ' AND dbvente.vente_detail.ID_Periode <= ' . $ide . ' ' .' ORDER BY dbvente.periode.An DESC'); ?> <table border="2" width="100%" cellpadding="3"> <?php while ($donnees = $reponse->fetch()) { if($annee != $donnees['An']){ echo '<tr>'; echo '<th colspan="6">' . $donnees['An']. '</th>'; echo '<tr>'; echo '<th> Sous-Produits </th>'; echo '<th> Unité </th>'; echo '<th>Volume</th>'; echo '<th>Prix Moyen</th>'; echo '<th>Chiffre affaire devise</th>'; echo '<th>Chiffre affaire dinars</th>'; echo '</tr>'; echo '</tr>'; } echo '<tr><td>' . htmlspecialchars($donnees['Nom_Sous_Produit']) . '</td>'; echo '<td>' . $donnees['Nom_Unite']. '</td>'; echo '<td>' . $donnees['Volume']. '</td>'; if ($donnees['Prix']!=0){ echo '<td>' . $donnees['Prix']. '</td>';}else{echo '<td>ND</td>';} if ($donnees['CA']!=0){ echo '<td>' . $donnees['CA']. '</td>';}else{echo '<td>ND</td>';} if ($donnees['CA_Dinars']!=0){ echo '<td>' . $donnees['CA_Dinars']. '</td>';}else{echo '<td>ND</td>';} $annee = $donnees['An']; } ?> </table> <?php } else { if($idf>0) { /*afficher toutes les ventes réalisées de la famille je manipile à ce niveau la table vente globale*/ $reponse = $bdd->query('SELECT dbvente.periode.An, dbvente.produit.Nom_Produit, dbvente.unites.ID_Unite, dbvente.vente.Volume, dbvente.vente.Prix, dbvente.vente.CA, dbvente.vente.CA_Dinars FROM dbvente.periode, dbvente.produit, dbvente.vente, dbvente.unites WHERE dbvente.vente.ID_Periode = dbvente.periode.ID_Periode AND dbvente.vente.ID_Produit = dbvente.produit.ID_Produit AND dbvente.vente.ID_unite = dbvente.unites.ID_Unite AND dbvente.vente.ID_Marche = 2 AND dbvente.vente.ID_Famille = ' . $idf . ' ' . 'AND dbvente.vente.ID_Periode <= ' . $ide . ' '.' ORDER BY dbvente.periode.An DESC'); ?> <table border="2" width="100%" cellpadding="3"> <?php while ($donnees = $reponse->fetch()) { if($annee != $donnees['An']){ echo '<tr>'; echo '<th colspan="6">' . $donnees['An']. '</th>'; echo '<tr>'; echo '<th> Produit </th>'; echo '<th> Unité </th>'; echo '<th>Volume</th>'; echo '<th>Prix Moyen</th>'; echo '<th>Chiffre affaire devise</th>'; echo '<th>Chiffre affaire dinars</th>'; echo '</tr>'; echo '</tr>'; } echo '<tr><td>' . htmlspecialchars($donnees['Nom_Produit']) . '</td>'; echo '<td>' . $donnees['Nom_Unite']. '</td>'; echo '<td>' . $donnees['Volume']. '</td>'; if ($donnees['Prix']!=0){ echo '<td>' . $donnees['Prix']. '</td>';}else{echo '<td>ND</td>';} if ($donnees['CA']!=0){ echo '<td>' . $donnees['CA']. '</td>';}else{echo '<td>ND</td>';} if ($donnees['CA_Dinars']!=0){ echo '<td>' . $donnees['CA_Dinars']. '</td>';}else{echo '<td>ND</td>';} $annee = $donnees['An']; } ?> </table> <?php } } } } } //SINON else{ /*A ce niveau tout l'historique est à prendre en considération*/ if($idd>0) { $reponse = $bdd->query('SELECT dbvente.periode.An, dbvente.sous_produit_detail.Nom_Sous_Produit_Detail, dbvente.unites.Nom_Unite, dbvente.vente_sous_detail.Volume, dbvente.vente_sous_detail.Prix, dbvente.vente_sous_detail.CA, dbvente.vente_sous_detail.CA_Dinars FROM dbvente.vente_sous_detail, dbvente.sous_produit_detail, dbvente.periode, dbvente.produit, dbvente.sous_produit, dbvente.unites, dbvente.famille_produit WHERE dbvente.famille_produit.ID_Famille = ' . $idf . ' AND dbvente.produit.ID_Produit = ' . $idp . ' AND dbvente.sous_produit.ID_Sous_Produit = ' . $ids . ' AND dbvente.vente_sous_detail.ID_Marche = 2 AND dbvente.sous_produit_detail.ID_Sous_Produit_Detail = ' . $idd . ' AND dbvente.vente_sous_detail.ID_Periode = dbvente.periode.ID_Periode AND dbvente.vente_sous_detail.ID_Sous_Produit_Detail = dbvente.sous_produit_detail.ID_Sous_Produit_Detail AND dbvente.sous_produit_detail.ID_Sous_Produit = dbvente.sous_produit.ID_Sous_Produit AND dbvente.sous_produit.ID_Produit = dbvente.produit.ID_Produit AND dbvente.vente_sous_detail.ID_Unite = dbvente.unites.ID_Unite AND dbvente.famille_produit.ID_Famille = dbvente.produit.ID_Famille ORDER BY dbvente.periode.An DESC'); ?> <table border="2" width="100%" cellpadding="3"> <?php while ($donnees = $reponse->fetch()) { if($annee != $donnees['An']){ echo '<tr>'; echo '<th colspan="6">' . $donnees['An']. '</th>'; echo '<tr>'; echo '<th> Sous-Produits </th>'; echo '<th> Unité </th>'; echo '<th>Volume</th>'; echo '<th>Prix Moyen</th>'; echo '<th>Chiffre affaire devise</th>'; echo '<th>Chiffre affaire dinars</th>'; echo '</tr>'; echo '</tr>'; } echo '<tr><td>' . htmlspecialchars($donnees['Nom_Sous_Produit_Detail']) . '</td>'; echo '<td>' . $donnees['Nom_Unite']. '</td>'; echo '<td>' . $donnees['Volume']. '</td>'; if ($donnees['Prix']!=0){ echo '<td>' . $donnees['Prix']. '</td>';}else{echo '<td>ND</td>';} if ($donnees['CA']!=0){ echo '<td>' . $donnees['CA']. '</td>';}else{echo '<td>ND</td>';} if ($donnees['CA_Dinars']!=0){ echo '<td>' . $donnees['CA_Dinars']. '</td>';}else{echo '<td>ND</td>';} $annee = $donnees['An']; } ?> </table> <?php } //SINON else { //SI produit selectionné ALORS if($ids>0) { /*afficher toutes les ventes réalisées du sous produit je manipule à ce niveau la table vente de sous produit et la table détail*/ $reponse = $bdd->query('SELECT dbvente.periode.An, dbvente.sous_produit_detail.Nom_Sous_Produit_Detail, dbvente.unites.Nom_Unite, dbvente.vente_sous_detail.Volume, dbvente.vente_sous_detail.Prix, dbvente.vente_sous_detail.CA, dbvente.vente_sous_detail.CA_Dinars FROM dbvente.vente_sous_detail, dbvente.sous_produit_detail, dbvente.periode, dbvente.produit, dbvente.sous_produit, dbvente.unites, dbvente.famille_produit WHERE dbvente.famille_produit.ID_Famille = ' . $idf . ' AND dbvente.produit.ID_Produit = ' . $idp . ' AND dbvente.sous_produit.ID_Sous_Produit = ' . $ids . ' AND dbvente.vente_sous_detail.ID_Marche = 2 AND dbvente.vente_sous_detail.ID_Periode = dbvente.periode.ID_Periode AND dbvente.vente_sous_detail.ID_Sous_Produit_Detail = dbvente.sous_produit_detail.ID_Sous_Produit_Detail AND dbvente.sous_produit_detail.ID_Sous_Produit = dbvente.sous_produit.ID_Sous_Produit AND dbvente.sous_produit.ID_Produit = dbvente.produit.ID_Produit AND dbvente.vente_sous_detail.ID_Unite = dbvente.unites.ID_Unite AND dbvente.famille_produit.ID_Famille = dbvente.produit.ID_Famille ORDER BY dbvente.periode.An DESC'); ?> <table border="2" width="100%" cellpadding="3"> <?php while ($donnees = $reponse->fetch()) { if($annee != $donnees['An']){ echo '<tr>'; echo '<th colspan="6">' . $donnees['An']. '</th>'; echo '<tr>'; echo '<th> Sous-Produits </th>'; echo '<th> Unité </th>'; echo '<th>Volume</th>'; echo '<th>Prix Moyen</th>'; echo '<th>Chiffre affaire devise</th>'; echo '<th>Chiffre affaire dinars</th>'; echo '</tr>'; echo '</tr>'; } echo '<tr><td>' . htmlspecialchars($donnees['Nom_Sous_Produit_Detail']) . '</td>'; echo '<td>' . $donnees['Nom_Unite']. '</td>'; echo '<td>' . $donnees['Volume']. '</td>'; if ($donnees['Prix']!=0){ echo '<td>' . $donnees['Prix']. '</td>';}else{echo '<td>ND</td>';} if ($donnees['CA']!=0){ echo '<td>' . $donnees['CA']. '</td>';}else{echo '<td>ND</td>';} if ($donnees['CA_Dinars']!=0){ echo '<td>' . $donnees['CA_Dinars']. '</td>';}else{echo '<td>ND</td>';} $annee = $donnees['An']; } ?> </table> <?php } //SINON else { //SI sous produit selectionné ALORS if($idp>0) { /*afficher toutes les ventes réalisées du produit je manipile à ce niveau la table vente globale et la table de vente de sous produit*/ $reponse = $bdd->query('SELECT dbvente.periode.An, dbvente.sous_produit.Nom_Sous_Produit, dbvente.unites.Nom_Unite, dbvente.vente_detail.Volume, dbvente.vente_detail.Prix, dbvente.vente_detail.CA, dbvente.vente_detail.CA_Dinars FROM dbvente.periode, dbvente.sous_produit, dbvente.vente_detail, dbvente.produit, dbvente.famille_produit, dbvente.unites WHERE dbvente.vente_detail.ID_Periode = dbvente.periode.ID_Periode AND dbvente.vente_detail.ID_Sous_Produit = dbvente.sous_produit.ID_Sous_Produit AND dbvente.sous_produit.ID_Produit = dbvente.produit.ID_Produit AND dbvente.produit.ID_Famille = dbvente.famille_produit.ID_Famille AND dbvente.vente_detail.ID_Unite = dbvente.unites.ID_Unite AND dbvente.vente_detail.ID_Marche = 2 AND dbvente.famille_produit.ID_Famille = ' . $idf . ' AND dbvente.sous_produit.ID_Produit = ' . $idp . ' '.' ORDER BY dbvente.periode.An DESC'); ?> <table border="2" width="100%" cellpadding="3"> <?php while ($donnees = $reponse->fetch()) { if($annee != $donnees['An']){ echo '<tr>'; echo '<th colspan="6">' . $donnees['An']. '</th>'; echo '<tr>'; echo '<th> Sous-Produits </th>'; echo '<th> Unité </th>'; echo '<th>Volume</th>'; echo '<th>Prix Moyen</th>'; echo '<th>Chiffre affaire devise</th>'; echo '<th>Chiffre affaire dinars</th>'; echo '</tr>'; echo '</tr>'; } echo '<tr><td>' . htmlspecialchars($donnees['Nom_Sous_Produit']) . '</td>'; echo '<td>' . $donnees['Nom_Unite']. '</td>'; echo '<td>' . $donnees['Volume']. '</td>'; if ($donnees['Prix']!=0){ echo '<td>' . $donnees['Prix']. '</td>';}else{echo '<td>ND</td>';} if ($donnees['CA']!=0){ echo '<td>' . $donnees['CA']. '</td>';}else{echo '<td>ND</td>';} if ($donnees['CA_Dinars']!=0){ echo '<td>' . $donnees['CA_Dinars']. '</td>';}else{echo '<td>ND</td>';} $annee = $donnees['An']; } ?> </table> <?php } else { if($idf>0) { /*afficher toutes les ventes réalisées de la famille je manipile à ce niveau la table vente globale*/ $reponse = $bdd->query('SELECT dbvente.periode.An, dbvente.produit.Nom_Produit, dbvente.unites.Nom_Unite, dbvente.vente.Volume, dbvente.vente.Prix, dbvente.vente.CA, dbvente.vente.CA_Dinars FROM dbvente.periode, dbvente.produit, dbvente.vente, dbvente.unites WHERE dbvente.vente.ID_Periode = dbvente.periode.ID_Periode AND dbvente.vente.ID_Produit = dbvente.produit.ID_Produit AND dbvente.vente.ID_Unite = dbvente.unites.ID_Unite AND dbvente.vente.ID_Marche = 2 AND dbvente.vente.ID_Famille = ' . $idf . ' ' . ' ORDER BY dbvente.periode.An DESC'); ?> <table border="2" width="100%" cellpadding="3"> <?php while ($donnees = $reponse->fetch()) { if($annee != $donnees['An']){ echo '<tr>'; echo '<th colspan="6">' . $donnees['An']. '</th>'; echo '<tr>'; echo '<th> Produit </th>'; echo '<th> Unité </th>'; echo '<th>Volume</th>'; echo '<th>Prix Moyen</th>'; echo '<th>Chiffre affaire devise</th>'; echo '<th>Chiffre affaire dinars</th>'; echo '</tr>'; echo '</tr>'; } echo '<tr><td>' . htmlspecialchars($donnees['Nom_Produit']) . '</td>'; echo '<td>' . $donnees['Nom_Unite']. '</td>'; echo '<td>' . $donnees['Volume']. '</td>'; if ($donnees['Prix']!=0){ echo '<td>' . $donnees['Prix']. '</td>';}else{echo '<td>ND</td>';} if ($donnees['CA']!=0){ echo '<td>' . $donnees['CA']. '</td>';}else{echo '<td>ND</td>';} if ($donnees['CA_Dinars']!=0){ echo '<td>' . $donnees['CA_Dinars']. '</td>';}else{echo '<td>ND</td>';} $annee = $donnees['An']; } ?> </table> <?php } } } } } } } ?>

Re: Tableau croisé dynamique

par master2011 » 29 août 2012, 12:39

Voila le code du formulaire:

Code : Tout sélectionner

<?php try { $bdd = new PDO('mysql:host=localhost;dbname=dbvente', 'root', 'mysql'); } catch(Exception $e){ die('Erreur : '.$e->getMessage()); } $idf = isset($_POST['famille']) ? $_POST['famille'] :null; //identifiant famille $idp = isset($_POST['produits']) ? $_POST['produits'] :null; //identifiant produit $ids = isset($_POST['sousproduits']) ? $_POST['sousproduits'] :null; //identifiant sous produit $idd = isset($_POST['spdetail']) ? $_POST['spdetail'] :null; //identifiant sous produit détail $idb = isset($_POST['du']) ? $_POST['du'] :null; //identifiant date début (begin) $ide = isset($_POST['au']) ? $_POST['au'] :null; //identifiant date fin (end) $vl = (isset($_POST['vl'])) ?$_POST['vl'] :null; //case à cocher pour la colonne des volumes $pm = (isset($_POST['pm'])) ?$_POST['pm'] :null; //case à cocher pour la colonne des prix moyens $cd = (isset($_POST['cd'])) ?$_POST['cd'] :null; //case à cocher pour la colonne des chiffres des affaires en devise $cl = (isset($_POST['cl'])) ?$_POST['cl'] :null; //case à cocher pour la colonne des chiffres des affaires en monnaie locale ?> <form id="chgdetail" action="<?php echo($_SERVER['PHP_SELF']); ?>" method="post"> <fieldset id="t0"> <fieldset id="t2"> <legend> Famille de produit </legend><br/> <label for="famille">Famille : </label> <select name="famille" id="famille" tabindex="1" onchange="document.forms['chgdetail'].submit();"> <br/> <option value="-1">Toutes les familles</option> <?php /*-----------------------------Famille de produit--------------------------------*/ $reponse = $bdd->query('SELECT famille_produit.ID_Famille, famille_produit.Nom_Famille FROM famille_produit'); $code_famille=array(); $famille=array(); $nb_famille = 0; if($reponse != false){ while($ligne = $reponse->fetch(PDO::FETCH_ASSOC)){ array_push($code_famille, $ligne['ID_Famille']); array_push($famille, $ligne['Nom_Famille']); $nb_famille++; } } for($i=0; $i<$nb_famille; $i++){ ?> <option value="<?php echo($code_famille[$i]); ?>"<?php echo((isset($idf) && $idf == $code_famille[$i])?" selected=\"selected\"":null); ?>><?php echo($famille[$i]); ?></option> <?php //$reponse->closeCursor(); } ?> </select> <p tabindex="2"/> </fieldset> <fieldset id="t3"> <legend> Produits et Détails </legend><br/> <label for="produits">Produits : </label> <select name="produits" id="produits" tabindex="20" onchange="document.forms['chgdetail'].submit();"><br/> <option value="-1">Tous les produits</option> <?php /*-----------------------------------------Les produits -----------------------------------------*/ $reponse = $bdd->query('SELECT produit.ID_Produit, produit.Nom_Produit FROM produit WHERE produit.ID_Famille = '.$idf.''); $code_produit=array(); $produit=array(); $nb_produits = 0; if($reponse != false){ while($ligne = $reponse->fetch(PDO::FETCH_ASSOC)){ array_push($code_produit, $ligne['ID_Produit']); array_push($produit, $ligne['Nom_Produit']); $nb_produits++; } } for($i=0; $i<$nb_produits; $i++){ ?> <option value="<?php echo($code_produit[$i]); ?>"<?php echo((isset($idp) && $idp == $code_produit[$i])?" selected=\"selected\"":null); ?>><?php echo($produit[$i]); ?></option> <?php $reponse->closeCursor(); } ?> </select></br> <br/><label for="sousproduits">Sous produits : </label> <select name="sousproduits" id="sousproduits" tabindex="21" onchange="document.forms['chgdetail'].submit();"><br/> <option value="-1">Tous les sous-produits</option> <?php /*-------------------------------------------------- Les sous produits --------------------------------*/ if(isset($idp) && $idp!=-1){ $reponse = $bdd->query('SELECT ID_Sous_Produit, Nom_Sous_Produit FROM sous_produit WHERE ID_Produit = ' . $idp .' '. 'ORDER BY ID_Sous_Produit'); $nsp = 0; $code_sousproduit = array(); $nom_sousproduit = array(); while($ligne_sousproduit = $reponse->fetch(PDO::FETCH_ASSOC)){ array_push($code_sousproduit, $ligne_sousproduit['ID_Sous_Produit']); array_push($nom_sousproduit, $ligne_sousproduit['Nom_Sous_Produit']); $nsp++; } for($d=0; $d<$nsp; $d++){ ?> <option value="<?php echo($code_sousproduit[$d]); ?>"<?php echo((isset($ids) && $ids == $code_sousproduit[$d])?" selected=\"selected\"":null); ?>><?php echo($nom_sousproduit[$d]); ?></option> <?php $reponse->closeCursor(); } } ?> </select><br/> <br/><label for="spdetail">Détail Sous produits : </label> <select name="spdetail" id="spdetail" tabindex="22" onchange="document.forms['chgdetail'].submit();"><br/> <option value="-1">Détail des sous-produits</option> <?php /*----------------------------------------- Détail des sous produits ---------------------------------------*/ if(isset($ids) && $ids!=-1){ $reponse = $bdd->query('SELECT sous_produit_detail.ID_Sous_Produit_Detail , sous_produit_detail.Nom_Sous_Produit_Detail FROM sous_produit_detail WHERE sous_produit_detail.ID_Sous_Produit = '. $ids .' '.' ORDER BY sous_produit_detail.ID_Sous_Produit_Detail'); $nspd = 0; $code_sousproduitdetail = array(); $nom_sousproduitdetail = array(); while($ligne_sousproduitdetail = $reponse->fetch(PDO::FETCH_ASSOC)){ array_push($code_sousproduitdetail, $ligne_sousproduitdetail['ID_Sous_Produit_Detail']); array_push($nom_sousproduitdetail, $ligne_sousproduitdetail['Nom_Sous_Produit_Detail']); $nspd++; } if($nspd !=0) { for($j=0; $j<$nspd; $j++){ ?> <option value="<?php echo($code_sousproduitdetail[$j]); ?>"<?php echo((isset($idd) && $idd == $code_sousproduitdetail[$j])?" selected=\"selected\"":null); ?>><?php echo($nom_sousproduitdetail[$j]); ?></option> <?php } $reponse->closeCursor(); } } ?> </select> <p tabindex="23"/> </fieldset> <!--------------------------------------- Critères de selection des périodes -----------------------------------------------> <fieldset id="t4"> <legend>Période</legend><br/> <label for="du">du : </label> <select name="du" id="du" tabindex="35"> <option value="-1">----</option> <?php $reponse = $bdd->query('SELECT DISTINCT periode.ID_Periode , periode.An FROM periode GROUP BY periode.An ORDER BY periode.An'); $npd = 0; $code_periodedebut = array(); $nom_periodedebut = array(); while($ligne_periodedebut = $reponse->fetch(PDO::FETCH_ASSOC)){ array_push($code_periodedebut, $ligne_periodedebut['ID_Periode']); array_push($nom_periodedebut, $ligne_periodedebut['An']); $npd++; } if($npd !=0) { for($j=0; $j<$npd; $j++){ ?> <option value="<?php echo($code_periodedebut[$j]); ?>"<?php echo((isset($idb) && $idb == $code_periodedebut[$j])?" selected=\"selected\"":null); ?>><?php echo($nom_periodedebut[$j]); ?></option> <?php } $reponse->closeCursor(); } ?> </select> <label for="au">au : </label> <select name="au" id="au" tabindex="36"><br/> <option value="-1">----</option> <?php $reponse = $bdd->query('SELECT DISTINCT periode.ID_Periode , periode.An FROM periode GROUP BY periode.An ORDER BY periode.An'); $npf = 0; $code_periodefin = array(); $nom_periodefin = array(); while($ligne_periodefin = $reponse->fetch(PDO::FETCH_ASSOC)){ array_push($code_periodefin, $ligne_periodefin['ID_Periode']); array_push($nom_periodefin, $ligne_periodefin['An']); $npf++; } if($npf !=0) { for($j=0; $j<$npf; $j++){ ?> <option value="<?php echo($code_periodefin[$j]); ?>"<?php echo((isset($ide) && $ide == $code_periodefin[$j])?" selected=\"selected\"":null); ?>><?php echo($nom_periodedebut[$j]); ?></option> <?php } $reponse->closeCursor(); } ?> </select> <p tabindex="23"/> </fieldset> <!--------------------------------------- Critères de selection des unités de mesures --------------------------------------> <fieldset id="t5"> <legend>Unités</legend><br/> <label for="unite">unités: </label> <select name="unite" id="unite" tabindex="45"><br/> <option value="-1">----</option> <?php $reponse = $bdd->query('SELECT DISTINCT unites.Nom_Unite FROM unites'); while ($donnees = $reponse->fetch()) { echo '<option value="choix">'.$donnees['Nom_Unite'].'</option>'; } $reponse->closeCursor(); ?> </select> <p tabindex="23"/> </fieldset> <!--------------------------------------- Choix des colonnes à afficher ----------------------------------------------------> <p></p> <fieldset id="t6"> <legend>Choix des informations à afficher</legend><br/> <input type="checkbox" name="vl" value="on" checked="checked" /> Volume<br/><br/> <input type="checkbox" name="pm" value="on" checked="checked" /> Prix Moyen<br/><br/> <input type="checkbox" name="cd" value="on" checked="checked" /> Chiffre d'affaire en US$<br/><br/> <input type="checkbox" name="cl" value="on" checked="checked" /> Chiffre d'affaire en DA<br/><br/> </fieldset> <!--------------------------------------- Mise en forme finale du formulaire -----------------------------------------------> <p> <input id="recherche" name="recherche" type="submit" value="Rechercher" /> <input id="reinitialiser" name="reinitialiser" type="reset" /> </p> </fieldset> <fieldset id="t6"> <legend>Résultat</legend><br/> <p>Affichage tabulaire du résultat de la recherche</p> </fieldset> </form>

Re: Tableau croisé dynamique

par master2011 » 29 août 2012, 11:48

Bonjour :) ,

J'ai un peu bossé les idées proposées et pour le moment j'ai mis en place ce code en brouillon,

Code : Tout sélectionner

<form method='POST' action='table.php'> <p></p> <fieldset id="t6"> <legend>Choix des informations à afficher</legend><br/> <input type="checkbox" name="vl" value="on" checked="checked"/> Volume<br/><br/> <input type="checkbox" name="pm" value="on" checked="checked"/> Prix Moyen<br/><br/> <input type="checkbox" name="cd" value="on" checked="checked"/> Chiffre d'affaire en US$<br/><br/> <input type="checkbox" name="cl" value="on" checked="checked"/> Chiffre d'affaire en DA<br/><br/> <input type="submit" value="Envoyer"> </fieldset> </form> <table border="2" width="auto" cellpadding="3"> <?php $vl = (isset($_POST['vl']))?$_POST['vl']:null; $pm = (isset($_POST['pm']))?$_POST['pm']:null; $cd = (isset($_POST['cd']))?$_POST['cd']:null; $cl = (isset($_POST['cl']))?$_POST['cl']:null; echo '<tr>'; echo '<th> Produit </th>'; echo '<th> Unité </th>'; /*if($_POST['vl'] == 'on'){echo '<th>Volume</th>';} else{exit;} if($_POST['pm'] == 'on'){echo '<th>Prix Moyen</th>';} else{exit;} if($_POST['cd'] == 'on'){echo '<th>Chiffre affaire devise</th>';} else{exit;} if($_POST['cl'] == 'on'){echo '<th>Chiffre affaire dinars</th>';} else{exit;}*/ if(!empty($vl)){echo '<th>Volume</th>';} //else{exit;} if(!empty($pm)){echo '<th>Prix Moyen</th>';} //else{exit;} if(!empty($cd)){echo '<th>Chiffre affaire devise</th>';} //else{exit;} if(!empty($cl)){echo '<th>Chiffre affaire dinars</th>';} //else{exit;} echo '</tr>'; ?> </table>
Mais c vrai que c du pure dépannage pour illustert qq chose de concrêt, à coté de ça Moogli a totalement raison en gérant plus de colonnes ça devient un véritable merdier :!: .

Je vais manipuler mes tables et mon formulaireet vous le transmettre, ça sera surement plus claire.

A tte.

Re: Tableau croisé dynamique

par schim59 » 29 août 2012, 09:43

C'est pas super propre, j'ai pas le temps de finir. Et je suis pas sûr d'avoir compris ce que tu voulias faire.
Mais bon, en espérant que cela t'aide :

exemple en image :

http://ilovephp.dedicom.eu/tabdynamique/tab_dyn.php

la table concernée :
Image

Code : Tout sélectionner

Selections multiples ctrl+clic gauche : <form action="tab_dyn.php"> <select name="colonnes[]" size="4" multiple> <fieldset> <option value="id">ID produit</option> <option value="famille">Famille de produit</option> <option value="produit">produit</option> <option value="ss_produit">sous produit</option> </select> <input type="submit"/> </form> <?php $i=0; foreach($_REQUEST['colonnes'] as $option ){ $i++; $col[$i]=$option; } //requete a la base include('cnx-ilp.php'); $j=0; $sql0="SELECT * FROM produits"; $sql1=$cnx->query($sql0); $result0=$sql1->fetchAll(PDO::FETCH_ASSOC); foreach($result0 as $row){ $j++; $tab[$j]=array($row['id'],$row['famille'],$row['produit'],$row['sous_produit']); } echo $j; echo "<br>"; print_r($col); echo "<br>"; if(in_array('id',$col)){ echo "*1*"; for ($k=0;$k<=$j;$k++){ echo $tab[$k][0]; echo "<br>"; } } if(in_array('famille',$col)){ echo "*2*"; for ($k=0;$k<=$j;$k++){ echo $tab[$k][1]; echo "<br>"; }} if(in_array('produit',$col)){ echo "*3*"; for ($k=0;$k<=$j;$k++){ echo $tab[$k][2]; echo "<br>"; } } if(in_array('ss_produit',$col)){ echo "*4*"; for ($k=0;$k<=$j;$k++){ echo $tab[$k][3]; echo "<br>"; } } ?>

Re: Tableau croisé dynamique

par Mazarini » 28 août 2012, 14:45

Bonjour,

Il me semble que :
- le choix des colonnes correspond au choix des colonnes, donc au paramétrage du select colonne1, colonne2...
- le choix des lignes correspond au niveau de détail, donc soit une jointure avec les tables adéquates soit l'utilisation d'un group by

Eventuellement tu peux ajouter des critères sur des produits...

Re: Tableau croisé dynamique

par moogli » 28 août 2012, 13:36

Salut,

Pour être hônnete, je comprend un peu l'idée générale, mais pas du tout la méthode :?: .

Comme je débute avec php, essayer SVP d'être peu plus explicite, je suis perdu la :oops: ,

Merci encore :) .
Ta demande étant générique on ne peux que l'être aussi.

Si tu nous donne exemple concret peux être pourrons "mieux" t'aider.

Ton exemple est bon pour un certain nombre de ligne mais, par exemple faire la même chose en mettant les libellés sur les lignes et stupide car tu peux avoir un nombre de colonne "infini" et la c'est le merdier ;) (sans parler de la lisibilité de la chose).

Tu as donc des possibilités à toi de nous dire ce que tu veux précisément !

@+

Re: Tableau croisé dynamique

par schim59 » 28 août 2012, 13:24

C'est un select.

une ensemble de "<option> </option>" qui sont des cases a cocher.

avec le
foreach($_request["nom_du_select"] as $option) 
Ca te génère une liste des valeurs cochées.Qu'il reste a traiter.

Re: Tableau croisé dynamique

par master2011 » 28 août 2012, 13:20

Salut,

Pour être hônnete, je comprend un peu l'idée générale, mais pas du tout la méthode :?: .

Comme je débute avec php, essayer SVP d'être peu plus explicite, je suis perdu la :oops: ,

Merci encore :) .

Re: Tableau croisé dynamique

par schim59 » 28 août 2012, 13:11

Bonjour,
Je ferai aussi, des id="" dans les <td> a afficher ou pas avec du javascript(JQuery pour ma préférence).

[javascript]
$.("#id_de la colonne").hide().
$.("#titre colonne").toggle(){
$.("#id_de la colonne").slidedDown();},
$.("#id_de la colonne").slideUp();
[/javascript]

Etant au travail j'ai pas le temps de bien rédiger le code,
je ferais ce soir et j'édite.
en attendant : http://www.w3schools.com/jquery/eff_toggle.asp

on doit pouvoir faire quelque chose en ajax aussi je pense, en refaisant une nouvelle requête a chaque modif, vu qu'il n'y a un qu'ne personne qui consulte.
Bon codage.

Re: Tableau croisé dynamique

par moogli » 28 août 2012, 12:35

html + JS

utiliser le champ html canevas ?

un formulaire tous con en indiquant une liste déroulante pour l'emplacement

par exemple

Tu commence par afficher deux champs pour demander le nombre de ligne et le nombre de colonne

Un bouton qui te permet de générer (en JS) un formulaire qui contient le nombre de champ nécessaire pour décrire le résultat.

par exemple champ 1 <input type="text" name="champ[1]" /><select name="place[1]"><option value=""></option><br />

le contenu du select peux changer dynamiquement en fonction de ce qui est déjà choisis :)

c'est pas super sexy mais utilisable.

tu peux utiliser la balise html canevas et du JS pour indiquer des objet à déplacer (comme l'ojet dragggable de JQueryui, et surement la même chose chez les concurrents).


@+

Re: Tableau croisé dynamique

par master2011 » 28 août 2012, 12:24

Salut,
si tu propose une interface permettant de faire ces choix, tu peu t'en servir pour construire le tableau final.
Et comment construire justement cette interface :?:

Merci.