Bonsoir,
premièrement je suis désolé si mon sujet semble banale.
Donc, j'ai un tableau rempli a partir de MySql, ce que je veut faire c'est de inverser l'opération et enregistrer mon tableau dans la base avec un clic sur bouton notant que les colonnes du tableau varient en nombre, parfois le tableau contient 8 colonnes en max et 3 colonnes en min, je veut donc insérer dans la base le tableau avec les colonnes qui y contient.
ce qui me bloque c'est comment récupérer le tableau du ajax dans une autre page PHP dans laquelle je vais exécuter ma requête d'insertion
Fichier : newSeg.php
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 <form name="userTable" id="table"> <input type="text" data-type="search" id="filterable-input"> <table id="table" data-role="table" data-mode="columntoggle" class="ui-responsive table-stroke" data-filter="true" data-input="#filterable-input" class="table table-striped table-bordered table-hover"> <thead> <tr> <th id="Nom" name="nom[]">Nom</th> <th id="Prénom" name="prenom[]">Prénom</th> <th data-priority="5" id="Mail[]">Mail</th> <th data-priority="5" id="Pays[]">Pays</th> <th data-priority="5" id="Civilité[]">Civilité</th> <th data-priority="5" id="Naissance[]">Naissance</th> <th data-priority="5" id="Inscription[]">Inscription</th> <th data-priority="5" id="Profession[]">Profession</th> </tr> </thead> <tbody> <?php for ($i=0;$i<count($u);$i++) { ?> <tr> <td><?php print $u[$i]->get_nom();?></td> <td><?php print $u[$i]->get_prenom();?></td> <td><?php print $u[$i]->get_email();?></td> <td><?php print $u[$i]->get_pays();?></td> <td><?php print $u[$i]->get_civilite();?></td> <td><?php print $u[$i]->get_date_n();?></td> <td><?php print $u[$i]->get_date_ins();?></td> <td><?php print $u[$i]->get_profession(); ?></td> </tr> <?php } ?> <tr><td><button type="button" class="btn btn-success" id="save">Enregistrer</button></td></tr> <input type="text" name="SegmentName" placeholder="nom du segment" width="50px"> </tbody> </table> </form> <script> $(document).ready(function(){ $('#save').click(function(){ var rowsArray = {}; var i = 0; $('#table tr').each(function({ rowsArray[i] = $(this).val(); // if you want to save the values of each row i++; $.ajax({ url: "SaveSegment.php", method: "POST", //data:$('#userTable').serialize(), data: { myarray : rowsArray }, success: function(result) { alert(data) $('#result').html(data); } }); }); }); }); </script>
Partager