Bonjour à tous, je fais appel à votre aide pour un petit soucis.
Je dispose d'une table utilisateurs contenant une liste de login avec leur mot de passe leur nom complet et leurs services corespondant.
J'ai réaliser l'affichage de cette liste avec la possibiliter de trier la liste par colonne. (Ordre alphabétique par login ou mot de passe etc en cliquant sur la colonne corespondante)
De plus j'ai ajouter à cette page un moteur de recherche pour retrouver des données plus facilement dans ma table d'utilisateurs.
Voila le code de la page, jusque la tous va bien cette page fonctionne parfaitement.
Mais lors de la recherche par mot clé, les resultats s'affichent bien cependant lorsque je veux trier ces résultats en cliquant sur la colonne que je souhaite, cela ne me tri pas uniquement les resultats de ma recherche mais toutes la table ! Du coup lorsque je veux trier une recherche, celle-ci est totalement inutile
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
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 <?php $db = mysql_connect('localhost','root',''); mysql_select_db('inventaire',$db); $tablename = 'utilisateur, services'; $tri_autorises = array('login','MDP','nom_complet', 'service'); $order_by = in_array($_GET['order'], $tri_autorises) ? $_GET['order'] : 'login'; $order_dir = isset($_GET['inverse']) ? 'DESC' : 'ASC'; $sql = " SELECT login, MDP, nom_complet, service FROM {$tablename} WHERE services.ID_SERVICE = utilisateur.ID_SERVICE ORDER BY {$order_by} {$order_dir} "; $result = mysql_query($sql); function sort_link($text, $order=false) { global $order_by, $order_dir; if(!$order) $order = $text; $link = '<a href="?order=' . $order; if($order_by==$order && $order_dir=='ASC') $link .= '&inverse=true'; $link .= '"'; if($order_by==$order && $order_dir=='ASC') $link .= ' class="order_asc"'; elseif($order_by==$order && $order_dir=='DESC') $link .= ' class="order_desc"'; $link .= '>' . $text . '</a>'; return $link; } // Affichage ?> <style type="text/css"> a.order_asc, a.order_desc:hover { padding-right:15px; background:transparent url(s_asc.png) right no-repeat; } a.order_desc, a.order_asc:hover { padding-right:15px; background:transparent url(s_desc.png) right no-repeat; } </style> <table border="1" width="100%"> <tr> <th><?php echo sort_link('Login', 'login') ?></th> <th><?php echo sort_link('Mot de passe', 'MDP') ?></th> <th><?php echo sort_link('Nom complet', 'nom_complet') ?></th> <th><?php echo sort_link('Service', 'service') ?></th> </tr> <?php while( $row=mysql_fetch_assoc($result) ) : ?> <tr> <td><?php echo $row['login'] ?></td> <td><?php echo $row['MDP'] ?></td> <td><?php echo $row['nom_complet'] ?></td> <td><?php echo $row['service'] ?></td> </tr> <?php endwhile ?>
Voila la plage recherche2.php qui pose problème
Merci d'avance
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
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
73
74
75
76
77
78
79
80
81
82
83 <?php if ($_POST['recherche'] == "" ) { //on redirige le visiteur sur la page de recherche header('location: utilisateurs.php?msg=Veuillez+indiquer+le+mot+recherché+!'); }else{ //Importation du fichier de configuration require_once('config.inc.php'); $db = mysql_connect('localhost','root',''); mysql_select_db('inventaire',$db); $tablename = 'utilisateur, services'; $tri_autorises = array('login','MDP','NOM_COMPLET', 'SERVICE'); $order_by = in_array($_GET['order'], $tri_autorises) ? $_GET['order'] : 'login'; $order_dir = isset($_GET['inverse']) ? 'DESC' : 'ASC'; //requète de recherche $req = ("select login, MDP, NOM_COMPLET, SERVICE FROM {$tablename} WHERE services.ID_SERVICE = utilisateur.ID_SERVICE and ID_UTI IN(select ID_UTI from utilisateur where login LIKE '%".$_POST['recherche']."%' or MDP LIKE'%".$_POST['recherche']."%' or NOM_COMPLET LIKE '%".$_POST['recherche']."%' or SERVICE LIKE '%".$_POST['recherche']."%' ORDER BY {$order_by} {$order_dir} )"); $result = mysql_query($req); function sort_link($text, $order=false) { global $order_by, $order_dir; if(!$order) $order = $text; $link = '<a href="?order=' . $order; if($order_by==$order && $order_dir=='ASC') $link .= '&inverse=true'; $link .= '"'; if($order_by==$order && $order_dir=='ASC') $link .= ' class="order_asc"'; elseif($order_by==$order && $order_dir=='DESC') $link .= ' class="order_desc"'; $link .= '>' . $text . '</a>'; return $link; } if(empty($result)){ echo'<div><strong>Désolé mais aucun resultat ne correspond à votre demande</strong><br><br></div>'; } else{ ?> <table border="1" width="100%"> <tr> <th><?php echo sort_link('Login', 'login') ?></th> <th><?php echo sort_link('Mot de passe', 'MDP') ?></th> <th><?php echo sort_link('Nom complet', 'NOM_COMPLET') ?></th> <th><?php echo sort_link('Service', 'SERVICE') ?></th> </tr> <?php while( $row = mysql_fetch_assoc($result) ) : ?> <tr> <td><?php echo $row['login'] ?></td> <td><?php echo $row['MDP'] ?></td> <td><?php echo $row['NOM_COMPLET'] ?></td> <td><?php echo $row['SERVICE'] ?></td> </tr> <?php endwhile ?> </table> <?php![]()
Partager