| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 
 | function searchArticle($idGamme,$idCategorie,$idSCategorie,$idFamille,$idSFamille,$search,$page,$order) {
 
	/* 
	 * MOTEUR DE RECHERCHE DE LA TABLE ARTICLE
	 * Entrées : Identifiant de la gamme, Identifiant de la rubrique, Identifiant de la catégorie, Valeur de la recherche, Page de la liste, Type de tri
	 * Sorties : Renvoie la requete contenant tous les champs de la table Article associé à sa taxe, sa gamme et sa catégorie,
	 * et le nombre de résultat obtenu
	 */
 
 
 
	$sql="SELECT id_article, ta.id_taxe, ref_article, nom_article, description_article, prix_achat_article, bienfaits_article, conseils_article, ROUND(prix_vente_article,2) AS prix_vente_ht, afficher_article, gerer_stock_article, stock_max_article, stock_min_article, quantite_article, unite_gestion_article, conditionnement_article, conditionnement_vente_article, composition_article, poids_article, image1_article, image2_article, doc_article, date_ajout_article, date_modif_article, date_valid_article, statut_article, zoom_article, ta.id_gamme, ta.id_categorie, hit_article, port_offert,PROMO_ARTICLE";
	$sql.=", ROUND(ta.prix_vente_article * (1 + tt.valeur_taxe),2) AS prix_vente_ttc";
	$sql.=", tt.valeur_taxe";
	$sql.=", tg.nom_gamme";
	$sql.=", tc.nom_categorie";
	$sql.=", tfp.nom_famille, tf.nom_famille AS nom_sfamille";
	$sql.=" FROM ".TABLE_ARTICLE."  ta, ".TABLE_CATEGORIE." tc, ".TABLE_GAMME." tg, ".TABLE_TAXE." tt, FAMILLE tf , FAMILLE tfp";
	$sql.=" WHERE tg.id_gamme = ta.id_gamme";
	$sql.=" AND tc.id_categorie = ta.id_categorie";
	$sql.=" AND tt.id_taxe = ta.id_taxe";
	$sql.=" AND tf.id_famille = ta.id_famille";
	$sql.=" AND tfp.id_famille = tf.parent_id_famille";
	// Verification que l'article est bien valide
	$sql.=" AND ta.afficher_article = 1";
	$sql.=" AND (ta.date_valid_article='0000-00-00 00:00:00' OR ta.date_valid_article > NOW())";
 
	// Critères de recherche
	if($idGamme>0) $sql.=" AND ta.id_gamme = '".$idGamme."'";
	if($idCategorie!=0) $sql.=" AND tc.id_categorie = '".$idCategorie."'";
	if($idFamille!=0) $sql.=" AND tf.parent_id_famille = '".$idFamille."'";
	if($idSFamille!=0) $sql.=" AND tf.id_famille = '".$idSFamille."'";
	if(!empty($search)) $sql.=" AND (ta.nom_article LIKE '%".$search."%' OR ta.bienfaits_article LIKE '%".$search."%' OR ta.conseils_article LIKE '%".$search."%' OR ta.composition_article LIKE '%".$search."%')";
 
	// Calcul du nombre de résultats
	$req=mysql_query($sql);
	$nbResultat = mysql_num_rows($req);
 
	// Critères de tri
	switch($order) {
		case 1: // Nom
			$sql.=" ORDER BY ta.nom_article";
			break;
		case 2: // Gamme
			$sql.=" ORDER BY tg.nom_gamme, ta.nom_article";
			break;
		case 3: // Rubrique
			$sql.=" ORDER BY tfp.nom_famille, ta.nom_article";
			break;
		case 4: // Catégorie
			$sql.=" ORDER BY tc.nom_categorie, ta.nom_article";
			break;
		case 5: // Prix
			$sql.=" ORDER BY prix_vente_ttc, ta.nom_article";
			break;
		default:
			$sql.=" ORDER BY rang_article, ta.nom_article";
			break;
	}
 
	// Critères de limit
	$limit = $GLOBALS['resultatParPage'] * ($page-1);
	$sql.=" LIMIT ".$limit.", ".$GLOBALS['resultatParPage'];
	//echo $sql;
	// Calcul les stats relatifs ç la recherche
	$debutArticle = $limit+1;
	$finArticle = $GLOBALS['resultatParPage'];
	if($finArticle>$nbResultat) $finArticle=$nbResultat;
	$statResultat = array('debut_article' => $debutArticle,'fin_article' => $finArticle,'nb_article' => $nbResultat);
 
	return array(mysql_query($sql),$statResultat);
} | 
Partager