Bonjour à tous,
Adepte du PHP, je développe une solution de gestion de stock magasin. Lors de la rédaction d'un bon de commande, je souhaiterai pouvoir effectuer une recherche dans la base de données 'stock' à partir d'un input type text et d'un bouton 'rechercher'. Rien de plus simple me diriez vous !!! le problème : le rafraîchissement efface les éléments déjà saisi dans le bon le commande.
Je pense qu'il n'y a qu'une solution : Ajax !!!
Je souhaiterai charger la recherche suivante sans perte d'information. Genre InnerHTML...
Affichage du tableau de résultats :
Je reste convaincu que tout est possible !!! Auriez vous une solution ?
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 <?php // Connexion à la base de données include("menu//chiens.php"); // $_POST['recherche_article'] serait la valeur postée. // Recherche le nombre de résultats dans la base de données $result = $bdd->query("SELECT count(REF_INTERNE) FROM `stock` WHERE REF_INTERNE LIKE '%".$_POST['recherche_article']."%' OR REFERENCE_ORIGINE LIKE '%".$_POST['recherche_article']."%' OR REFERENCE_MARQUE_PROPOSEE LIKE '%".$_POST['recherche_article']."%' OR DESIGNATION LIKE '%".$_POST['recherche_article']."%' "); $row = $result->fetch(); $result->closeCursor(); $total = $row[0]; //========================================= // si on a récupéré un resultat on l'affiche. //========================================= if($total){ $resultats = $bdd->query("SELECT*FROM `stock` WHERE REF_INTERNE LIKE '%".$_POST['recherche_article']."%' OR REFERENCE_ORIGINE LIKE '%".$_POST['recherche_article']."%' OR REFERENCE_MARQUE_PROPOSEE LIKE '%".$_POST['recherche_article']."%' OR DESIGNATION LIKE '%".$_POST['recherche_article']."%' ORDER BY REF_INTERNE ASC limit 0,20"); // début du tableau echo ("<div id='tableau_resultats'>"); echo ("<table width='780'>\n"); echo ("<tr>"); echo ("<td colspan='11'><h1>Liste des articles trouvés...</h1></td>"); echo ("</tr>"); echo ("<tr>"); echo ("</tr>"); echo ("<tr>"); echo ("<td colspan='11'>Nbre référence(s) trouvée(s): <strong>".$total."</strong></td>"); echo ("</tr>"); echo ("<tr>"); echo ("<td width='25'><strong>ID</strong></td>"); echo ("<td width='35'><strong>REF VILLE</strong></td>"); echo ("<td width='160'><strong>DESIGNATION</strong></td>"); echo ("<td width='80'><strong>FOURNISSEUR</strong></td>"); echo ("<td width='45'><strong>REF FOURNISSEUR</strong></td>"); echo ("<td width='95'><strong>MARQUE</strong></td>"); echo ("<td width='35'><strong>STOCK</strong></td>"); echo ("<td width='40'><strong>PRIX (HT)</strong></td>"); echo ("<td width='30'><strong>GIS</strong></td>"); echo ("</tr>"); $i=0; // lecture et affichage des résultats sur 2 colonnes // On récupère tout le contenu de la table while($row = $resultats->fetch()){ //Récupération des variables $id= $row['ID']; $ref_ville = $row['REF_INTERNE']; $designation = $row['DESIGNATION']; $fournisseur = $row['FOURNISSEUR']; $ref_fournisseur = $row['REFERENCE_MARQUE_PROPOSEE']; $marque = $row['MARQUE_PROPOSEE']; $stock = $row['STOCK']; $prix = $row['PRIX_UNITAIRE_HT']; $gisement = $row['GISEMENT']; echo ("<tr bgcolor='".( ($i++ % 2 == 0) ? '#dddddd' : '#eeeeee' )."'>"); echo ("<td>".$id."</td>"); echo ("<td>".$ref_ville."</td>"); echo( "<td>".$designation."</td>"); echo( "<td>".$fournisseur."</td>"); echo( "<td>".$ref_fournisseur."</td>"); echo( "<td>".$marque."</td>"); echo( "<td>".$stock."</td>"); echo( "<td>".$prix."</td>"); echo( "<td>".$gisement."</td>"); echo ('</tr>'."\n"); echo ('</form>'); } echo ('</table></div>'."\n"); $resultats->closeCursor(); ?>
Partager