Bonjour à toutes et tous.
Je suis en train de coder un site et je souhaiterai faire un système de recherche comme Facebook avec affichage de profil pendant qu'on tape le nom ou le prénom de la personne.
J'ai un soucis et j'arrive pas à voir d'où ça vient. Voici mes codes :
page head.php :
Ma page index avec le formulaire :
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 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.js"></script> <script> $(document).ready(function(){ $('.loader').hide(); $('#search').keyup(function(){ $field = $(this); $('#result').html(''); if($field.val().length>1) { $.ajax({ type: 'post', url: 'recherches/resultats.php', data: 'search='+$('#search').val(), beforeSend:function(){ $('.loader').stop().fadeIn(); }, success: function(data){ $('.loader').fadeOut(); $('#search').html(data); } }); } }); }); </script>
La page de traitement :
Code html : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 <div id="resultSearch"> <form action="recherches/resultats.php" method="post"> <label for="search" style="color:#604938">Rechercher une personne que vous connaissez</label> <input type="text" name="search" id="search" class="inputSearchBarre"> <input type="submit" name="Envoi_Search" class="SearchButton" value=""> <div class="loader"></div> </form> <div id="result"></div> </div>
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 <?php session_start(); require_once('head.php'); if(empty($_POST['Envoi_Search']) AND !empty($_POST['search'])) { extract($_POST); $search = strip_tags($search); require('../include/config.php'); $reqSearch=$bdd->query("SELECT nom, prenom, photoProfil FROM membres WHERE nom LIKE '%$search%' OR prenom LIKE '%$search%' ORDER BY id LIMIT 0,8"); if($reqSearch->rowCount()>0){ while($data = $reqSearch->fetch(PDO::FETCH_OBJ)){ ?> <img src="./../img/photos/<?php echo htmlspecialchars($data->photoProfil); ?>" width="50" height"50" alt="<?php echo htmlspecialchars($data->photoProfil); ?>" title="Profil de <?php echo htmlspecialchars($data->prenom); ?> <?php echo htmlspecialchars($data->nom); ?>" style="float:left;margin:10px 5px 0 0"/> <?php echo '<div style="float:left;width:225px;margin-top:9px">'.htmlspecialchars($data->prenom).' '.htmlspecialchars($data->nom).'</div>'; echo '<br />'; } } else { echo htmlspecialchars('Aucun résultat. pas de chance !'); } } else { echo htmlspecialchars('Aucun résultat. ERREUR envoi formulaire'); } require_once('bottom.php'); ?>
Le souci est que le recherche s'effectue bien sur la page resultats.php avec la requête mais rien ne s'affiche sur l'index. J'ai une div qui doit afficher les possibilités directement dans ma div #result mais rien ne se passe.
Merci pour votre aide![]()
Partager