[PHP] Tableau tri dynamique

LeHigh Messages postés 121 Statut Membre -  
pyschopathe Messages postés 2053 Statut Membre -
Bonjour,

J'ai un tableau en PHP ou j'effectue un tri croissant/décroissant par colonnes, le problème c'est que auparavant je remplis un formulaire qui me renvoie que certains enregistrements de ma base, or, quand je veux trier mon tableau, ca rafraichis la page donc ca ré affiche toute les données de la base, et plus ce que j'avais déjà filtrer auparavant. Donc j'aimerais savoir s'il y a un moyen pour palier à ce problème ^^, merci.
A voir également:

3 réponses

Utilisateur anonyme
 
0
LeHigh Messages postés 121 Statut Membre 1
 
j'avais vu cette fonction dans la doc, mais dans mon cas je ne vois pas comment l'utiliser :/,

voici un screenshot qui représente le tableau

https://www.pixenli.com/image1244186991021340400.html

et le code (j'ai enlevé les trucs qui servent à rien)

if ($idconnect) {

error_reporting(E_ALL);

	if ($_REQUEST['p'] == n) {
		if (isset ($_REQUEST['t'])) {
			$tri = $_REQUEST['t'];
			$o = $_REQUEST['o'];
		} else {
			$tri = 'micro.num_uc';
			$o = 'ASC';
		}

	$ok = false;
	$ip = false;
	$name = $nom_util;
 	if ($num_uc != "") { 		$num_uc = "AND micro.num_uc LIKE '%".$num_uc."%' "; $ok = true; }
	if ($marque_uc != "") { 	$marque_uc = "AND uc.marque_uc LIKE '".$marque_uc."' "; $ok = true; }
	if ($type_uc != "") { 		$type_uc = "AND uc.type_uc LIKE '".$type_uc."' "; $ok = true; }

	if ($num_inv_uc != "") { 	$num_inv_uc = "AND uc.num_inv_uc LIKE '".$num_inv_uc."' "; $ok = true; }
	
	if ($nom_util != "") { 		$nom_user = "AND micro.nom_util LIKE '%".$nom_util."%'"; $ok = true; }
	if ($service != "") { 		$service = "AND micro.service LIKE '".$service."' "; $ok = true; }
	if ($unite != "") { 		$unite = "AND micro.unite LIKE '".$unite."' "; $ok = true; }

	
	if ($ok == true ) { // Si au moins un des critères a été renseigné

		$req = "SELECT * FROM micro, uc, ip "; // Création de la requête avec les table micro, uc et ecran

		$req .=	"WHERE micro.ref_uc = uc.ref_uc AND micro.ref_ip = ip.ref_ip "; // Jointures

		$req .= $num_uc." ";
		$req .= $nom_user." ";
		$req .= $service." ";
		$req .= $unite." ";
	        $req .= $marque_uc." ";
		$req .= $type_uc." ";
		$req .= "ORDER BY ".$tri." ".$o;
	
	} else { // Sinon, sélection de l'ensemble des micros
		$req = "SELECT * FROM micro, uc, ip WHERE micro.ref_uc = uc.ref_uc AND micro.ref_ip = ip.ref_ip ORDER BY ".$tri." ".$o;
	}

	$res = mysql_query($req) or die ('erreur MySQL : '.mysql_error());
	$num = mysql_num_rows($res);

	if ($res) {
			echo '<form name="selection" action="caract_micro.php" method="POST">';
			echo '<table width="100%">';
			echo '<tr><td width="100%" class="fondblanc_txtbleu14g" align="center">Résultat de la recherche</td></tr>';
				echo '<tr><td width="100%" class="fondblanc_txtbleu14g" align="center">'.$num.' fiches trouvées</td></tr>';
			echo '<tr><td height="10"></td></tr>';
			echo '<tr><td width="100%">';
				echo '<table width="100%" border=0 cellspacing=0>';
				echo '<tr class="fondjaunepale_txtbleu12g">';
				echo '<td width="3%">Choix</td>';
				echo '<td width="13.5%" align="center">N° du micro&nbsp;&nbsp;<a href="php_search.php?p=n&t=micro.num_uc&o=asc"><img src="../images/flecheu.gif" border=0></a>&nbsp&nbsp<a href="php_search.php?p=n&t=micro.num_uc&o=desc"><img src="../images/fleched.gif" border=0></a></td>';
				echo '<td width="13.5%" align="center">Marque&nbsp;&nbsp;<a href="php_search.php?p=n&t=uc.marque_uc&o=asc"><img src="../images/flecheu.gif" border=0></a>&nbsp&nbsp<a href="php_search.php?p=n&t=uc.marque_uc&o=desc"><img src="../images/fleched.gif" border=0></a></td>';
				echo '<td width="13.5%" align="center">Type&nbsp;&nbsp;<a href="php_search.php?p=n&t=uc.type_uc&o=asc"><img src="../images/flecheu.gif" border=0></a>&nbsp&nbsp<a href="php_search.php?p=n&t=uc.type_uc&o=desc"><img src="../images/fleched.gif" border=0></a></td>';
				echo '<td width="13.5%" align="center">Utilisateur&nbsp;&nbsp;<a href="php_search.php?p=n&t=micro.nom_util&o=asc"><img src="../images/flecheu.gif" border=0></a>&nbsp&nbsp<a href="php_search.php?p=n&t=micro.nom_util&o=desc"><img src="../images/fleched.gif" border=0></a></td>';
				echo '<td width="13.5%" align="center">Service&nbsp;&nbsp;<a href="php_search.php?p=n&t=micro.service&o=asc"><img src="../images/flecheu.gif" border=0></a>&nbsp&nbsp<a href="php_search.php?p=n&t=micro.service&o=desc"><img src="../images/fleched.gif" border=0></a></td>';
				echo '<td width="13.5%" align="center">Unité&nbsp;&nbsp;<a href="php_search.php?p=n&t=micro.unite&o=asc"><img src="../images/flecheu.gif" border=0></a>&nbsp&nbsp<a href="php_search.php?p=n&t=micro.unite&o=desc"><img src="../images/fleched.gif" border=0></a></td>';
				echo '<td width="13.5%" align="center">Adresse ip&nbsp;&nbsp;<a href="php_search.php?p=n&t=INET_ATON(ip)&o=asc"><img src="../images/flecheu.gif" border=0></a>&nbsp&nbsp<a href="php_search.php?p=n&t=INET_ATON(ip)&o=desc"><img src="../images/fleched.gif" border=0></a></td>';
				echo '</table>';
			echo '</td></tr><tr><td>';

	echo '<table width="100%" border=1 cellspacing=0>';
		$_SESSION['tab_micro'] = array();
		$i=0;
		while ($ligne = mysql_fetch_array ($res)) {
			$ref = $ligne[0];
			$num_m = $ligne[1];
			$marque = $ligne[16];
			$type = $ligne[17];
			$nom = $ligne[4];
			$service = $ligne [2];
			$unite = $ligne[3];
			$adrip = $ligne[9];
			
			$_SESSION['tab_micro'][$i] = $ref;
			
			//Affichage de la ligne correspondant à un micro
			echo '<tr class="fondblanc_txtbleu12">';
			echo '<td align="center" width="3%"><input type="radio" name="select" value="'.$ref.'"></td>';
			echo '<td width="12.5%">'.$num_m.'</td>';
			echo '<td id="plop" width="13.5%">'.$marque.'</td>';
			echo '<td width="13.5%">'.$type.'</td>';
			echo '<td width="13.5%">'.$nom.'</td>';
			echo '<td width="13.5%">'.$service.'</td>';
			echo '<td width="12.5%">'.$unite.'</td>';
			echo '<td width="13.5%">'.$adrip.'</td>';
			$i++;
		}

0
LeHigh Messages postés 121 Statut Membre 1
 
up, personne ne peut m'aider ou n'a des pistes sur la façon de faire ?
0
pyschopathe Messages postés 2053 Statut Membre 135
 
Ben sur ton lien de tri, tu rajoutes les paramètres correspondant à ta sélection...
0