Bonjour,
Depuis qlq temps j'ai fait des codes pour afficher le résultat de recherche sous forme tableau via un popup et récupérer dans une page mère.
code sql:
Code sql : 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 - Base de données: `cpu` -- Structure de la table `produit` CREATE TABLE IF NOT EXISTS `produit` ( `Identifiant` int(10) unsigned NOT NULL AUTO_INCREMENT, `Nom` varchar(100) DEFAULT NULL, `Prix` float DEFAULT NULL, `Vignette` varchar(100) DEFAULT NULL, `Categorie` int(11) DEFAULT NULL, PRIMARY KEY (`Identifiant`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ; -- -- Contenu de la table `produit` -- INSERT INTO `produit` (`Identifiant`, `Nom`, `Prix`, `Vignette`, `Categorie`) VALUES (1, 'Intel Pentium 4 2GHz', 245, 'vignette/p4.gif', 2), (2, 'Intel Celeron 4 2GHz', 145, 'vignette/celeron.gif', 2), (3, 'Barette DDR 512 Mo PC2100', 56, 'vignette/ddr.gif', 3), (4, 'Intel(R) Core(TM) i3-4005U 1.7GHz', 310, 'vignette/core_i3.gif', 2);
- page mère
.
Code html : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 <script type="text/javascript"> function open_infos() { window.open('rch_cpu.php','nom_de_ma_popup','menubar=no, scrollbars=no, top=100, left=100, width=800, height=400'); } </script> <p>Nom CPU: <input type="text" size="30" name="recherche" id="ch" value="" disabled /> <a href="#null" onclick="javascript:open_infos();"><img src="rech.gif" width="25" title="Rechercher CPU" class="pointer" /></a>
- page rch_cpu.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
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 <script type="text/javascript"> function recherche() { window.opener.document.getElementById('ch').value = document.getElementById('rch').value; window.close(); } </script> <form name="frm_add_eleve" id="frm_add_eleve" method="GET" action="rch_cpu.php"> <table> <tr> <td> Nom CPU </td> <td> <input type="text" size="50" name="recherche" /> </td> </tr> <tr> <td> </td> <td><input type="submit" value="Rechercher" /></td> </tr> </table> </form> <?php mysql_connect('localhost','root',''); mysql_select_db('CPU'); //On determine l'expression a rechercher if(isset($_GET['recherche'])) { $mot=@$_GET['recherche']; echo $mot; $req = 'SELECT * FROM produit WHERE Nom LIKE "%'.$mot.'%" ' ; $req .= ' order by Identifiant asc'; $requete = mysql_query($req); $nb=mysql_num_rows($requete); if($nb>0) { //Le formulaire de recherche ?> <h2>Résultats</h2> <table width="500" border="1" cellspacing="0" cellpadding="5"> <tr> <th>Choisir</th> <th>Nom</th> <th>Prix</th> <th>Vignette</th> <th>atégorie</th> </tr> <?php //On affiche les resultats while($dnn = mysql_fetch_array($requete)) { ?> <tr> <td><a href="javascript:recherche();" ><input type="hidden" value="<?php echo $dnn['Nom']; ?>" name="recherche" id="rch" />Choisir</a></td> <td><?php echo $dnn['Nom']; ?></td> <td><?php echo $dnn['Prix']; ?></td> <td><?php echo $dnn['Vignette']; ?></td> <td><?php echo $dnn['Catégorie']?> </td> </tr> <?php } } else { echo "<script language = \"javascript\"> alert(\"Aucin CPU !\"); document.location.href='rch_cpu.php'; </script>"; } } ?> </table>
Si j'ai choisi intel comme mot clé on a trois résultats et si j'ai clique sur choisir c'est toujour la premier ligne du tableau qu'on a récupéré.
Pourriez-vous m'aider.
Partager