<?php

	session_start();
	
	include('config_inc.php'); 	
	
        if($_SESSION['database']=="local")
          {
             $db_host    = "localhost";
             $db_user   = "root";
     	     $db_pass   = "";
    	     $db_name   = "boutique";
  	  }
	
	if($_SESSION['database']=="public")
	  {
  	     $db_host    = "sql2";
   	     $db_user   = "analogde";
 	     $db_pass   = "rainbow";
	     //$db_type   = "mysql";
	     $db_name   = "analogde";
	  }

		include("include.php");
	
	 	$table = "washer"; 
		
		$connexion = mysql_connect($db_host,$db_user,$db_pass); 
        	mysql_select_db($db_name, $connexion);
  
	  	$requete = "SELECT filtre FROM categorie WHERE table_article='$table'";	
   		$result = mysql_query($requete);
	   	$datas = mysql_fetch_array($result);
    	    	
   		// decoupe la chaine
		$champs_filtre = explode(",", $datas[0]);
		  
  		if($flag == true)
  	          {  echo "filtrage";
  		     $connexion = mysql_connect($db_host,$db_user,$db_pass); 
       	    	     mysql_select_db($db_name, $connexion);	        
  	             $retour_messages = mysql_query($req);
	             $nb_resultats_filtre = mysql_num_rows($retour_messages);
	  	  }
  	     
  	    	if($flag == false)
  	     	  {  echo "defaut";
  	     	     $connexion = mysql_connect($db_host,$db_user,$db_pass); 
		     mysql_select_db($db_name, $connexion);
  	             $result = mysql_query("SELECT * FROM $table"); 
  	             $nb_resultats_filtre = mysql_num_rows($result);
  	             echo ">>>>>> Resultats : " .$nb_resultats_filtre;
  	             $connexion = mysql_connect($db_host,$db_user,$db_pass); 
 		     mysql_select_db($db_name, $connexion);
	             $retour_messages = mysql_query("SELECT * FROM $table"); 	
  	          } 
	    
	  	 $sauvegarde = array(array()); 
	 	   
	  	 $ptr = 0;
	 	   
          	 while($data=mysql_fetch_assoc($retour_messages)) 
                      {
		    	$tab = array();
		    	$chaine = "";
		    
			$marque = $data['marque'];
	   		$prix_ttc = $data['prix_ttc'];
	 		$designation = $data['designation'];
	   		$reference = $data['reference'];
			$dispo = $data['dispo'];
	  		$s1 = $designation ." " .$reference;
	  		    
	       	   	$tab[] = $marque;
	       	   	$tab[] = $prix_ttc;
	       	   	$tab[] = $designation;
	       	   	$tab[] = $reference;
	       	   	$tab[] = $dispo;
	       	   	$tab[] = $s1;
			   
	    	    	$motif_underscore = '_';
		    	$espace = " ";
		  
		    	for($j=1; $j<count($champs_filtre); $j++) 
	                   {  $val = $champs_filtre[$j];
				 
			      if($j<count($champs_filtre) )
			        { $chaine = $chaine ." " .$val ." " .$data[$val] .",";
			        }
	
			   else {  $chaine = $chaine ." " .$val ." " .$data[$val] ;
			        }
				  
			   }
	
		     	if(preg_match('`\_`', $chaine))
		          { $chaine = str_replace($motif_underscore, $espace, $chaine);
		          }

		     	$tab[] = $chaine;	
		     
		     	// sauve dans le tableau multidimensionnel
        	     	$sauvegarde[$ptr] = $tab;
        	     
        	     	$ptr = $ptr + 1;
        	     
         	       }    
             		include('filtre_resultat.php'); 	
             		
             		
             		//header('Location:  ')
             		
             		//array_push($tableau, $donnees[0]);

			

?>
    
	
	  

