Bonjour,
J'ai trois pages, l'une où je fais ma recherche Page_recherche.php, l'une où j'ai mon script pour l'autocompletion Page_action.php et mon dernier script Page_affichage_produit.php où j'affiche les resultats de ma recherche.
Dans l'affichage de l'autocompletion, j'affiche les 4 premiers caractères d'un champ (ex. 0007 au lieu de 0007h) je peux avoir d'autres enregistrements en 0007 avec 0007u, 0007i, 0007p..., le but est d'afficher simplement un 0007 dans l'autocompletion et d'afficher les 0007u, 0007i, 0007p... dans la page produits où l'on aura une décomposition des articles liès au produit 0007.
J'arrive bien à afficher seulement un 0007 dans mon autocompletion avec un distinct et un substring(champ1,1,5), par contre dans ma page affichage des produits, je ne récupère pas le contenu de mon champ1, rien ne s'affiche. Comment puis récupérer le contenu de champ1 du coup.
Merci beaucoup pour votre aide
Voici mes scripts :
Page_recherche.php
Code html : 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 <!DOCTYPE html> <html lang="en"> <head> <!-- jQuery library --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> <!-- Popper JS --> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script> </head> <body> <p>recherche</p> <form autocomplete="off" action="page_affichage_produit.php" method="post"> <input type="text" name="search" id="search" class="input1" placeholder="recherche" name="keywords" > <button type="submit" name="submit" value="Search">recherche</button> <p class="list-group" id="show-list"> <!-- Reponse show-list --> </p> </form> <script type="text/javascript"> $(document).ready(function() { $("#search").keyup(function() { var searchText = $(this).val(); if(searchText != '') { $.ajax( { url: 'Page_action.php', method: 'post', data:{query:searchText}, success:function(response) { $("#show-list").html(response); } }); } else { $("#show-list").html(''); } }); $(document).on('click','a',function() { $("#search").val($(this).text()); $("#show-list").html(''); }); }); </script>
Page_action.php
Code php : 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 <?php if(isset($_POST['query'])){ $inpText = $_POST['query']; $query = "SELECT DISTINCT champ2, champ3, champ4, champ5, substring(champ1,1,5) AS champ1_2 FROM produits_vue WHERE champ1 LIKE '%$inpText%' OR champ2 LIKE '%$inpText%' OR champ3 LIKE '%$inpText%' OR champ4 LIKE '%$inpText%' OR champ5 LIKE '%$inpText%' ORDER BY champ1 limit 15 "; $result = $conn->query($query); if($result->num_rows>0){ while($row=$result->fetch_assoc()){ echo"<a href='#' class='list-group-item list-group-item-action border-1'>".$row['champ1_2']."</a>"; echo"<a href='#' class='list-group-item list-group-item-action border-1'>".$row['champ2']."</a>"; echo"<a href='#' class='list-group-item list-group-item-action border-1'>".$row['champ3']."</a>"; echo"<a href='#' class='list-group-item list-group-item-action border-1'>".$row['champ4']."</a>"; echo"<a href='#' class='list-group-item list-group-item-action border-1'>".$row['champ5']."</a>"; } } else { echo "No Record"; } } ?>
Et page_affichage_produit.php
Code php : 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 <?php if(isset($_POST['submit'])){ $data = $_POST['search']; $sql = "SELECT * FROM table WHERE champ1 ='$data' OR champ2 = '$data' OR champ3 = '$data' OR champ4 ='$data' OR champ5 ='$data' ORDER BY champ1 "; $result=$conn->query($sql); $row=$result->fetch_assoc(); echo"<a href='#' class='list-group-item list-group-item-action border-1'>".$row['champ1']."</a>"; echo"<a href='#' class='list-group-item list-group-item-action border-1'>".$row['champ2']."</a>"; echo"<a href='#' class='list-group-item list-group-item-action border-1'>".$row['champ3']."</a>"; echo"<a href='#' class='list-group-item list-group-item-action border-1'>".$row['champ4']."</a>"; echo"<a href='#' class='list-group-item list-group-item-action border-1'>".$row['champ5']."</a>"; } ?>
Merci et bon week-end
Partager