Convertir tableau php vers JavaScript

Résolu
vinkey33 Messages postés 92 Date d'inscription mercredi 9 décembre 2015 Statut Membre Dernière intervention 23 janvier 2021 - Modifié le 16 juin 2017 à 10:42
vinkey33 Messages postés 92 Date d'inscription mercredi 9 décembre 2015 Statut Membre Dernière intervention 23 janvier 2021 - 16 juin 2017 à 11:33
Bonjour je voudrais réaliser un tableau en JavaScript depuis la bas de donné (phpadmin) mais je ne vois comment procédé
pouvez vous m'aider?

voic mon tableau en PHP
<div id="Affectation">
<form method="post" action="Affectation_result.php" >
<div class="table-responsive" id="AffectationTable">
<table class="table table bordered">
<tr id="first-tr">
<td> </td>
<th>USER ID</th>
<th>Nom</th>
<th>Prenom</th>
<th>Num SIM</th>
<th>PIN Terminal</th>
<th>PIN SIM</th>
<th>Num EMEI</th>
<th>Date Debut</th>
<th>Date Fin</th>
<th>Vitre</th>
<th>Coque</th>
<th>Support Vehicule</th>
<th>Actif</th>
<th>Or Affectation1</th>
<th>Statut</th>
</tr>
<?php
while($row = mysqli_fetch_array($result)) {
?>
<tr id="<?php echo $row["USER_ID"]; ?>">
<td><input type="radio" name="select" class="del_customer" value="<?php echo $row["USER_ID"]; ?>" /></td>
<td><?php echo $row["USER_ID"]; ?></td>
<td><?php echo $row["Nom"]; ?></td>
<td><?php echo $row["Prenom"]; ?></td>
<td><?php echo $row["Num_SIM"]; ?></td>
<td><?php echo $row["PIN_Terminal"]; ?></td>
<td><?php echo $row["PIN_SIM"]; ?></td>
<td><?php echo $row["Num_IMEI"]; ?></td>
<td><?php echo $row["Date_Debut"]; ?></td>
<td><?php echo $row["Date_Fin"]; ?></td>
<td><?php echo $row["Vitre"]; ?></td>
<td><?php echo $row["Coque"]; ?></td>
<td><?php echo $row["Support_Vehicule"]; ?></td>
<td><?php echo $row["Actif"]; ?></td>
<td><?php echo $row["Or_Affectation1"]; ?></td>
<td><?php echo $row["Statut"]; ?></td>
</tr></div></div>
</form>

merci

1 réponse

jordane45 Messages postés 38138 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 17 avril 2024 344
16 juin 2017 à 11:08
Bonjour,

Pour relier du javascript à du php .... tu peux (dois....)passer par de l'ajax.
0
vinkey33 Messages postés 92 Date d'inscription mercredi 9 décembre 2015 Statut Membre Dernière intervention 23 janvier 2021
Modifié le 16 juin 2017 à 11:54
j'ai trouver un code en php en passant par jquery qui permet de créé le tableau mais parcontre je ne vois pas comment rajoute plus que deux variable du genre user, nom, prenom ...
liste.php
<?php

// appel du script de connexion
require('connexion.php');

//création d'un tableau
$json = array();

//vérification de la variable, si elle existe
if(isset($_GET['go']))
{

// requête qui récupère
$requete = "SELECT * FROM `vu_affect_empl`";

// exécution de la requête
$resultat = $bdd->query($requete) or die(print_r($bdd->errorInfo()));

// Création de la liste
while($donnees = $resultat->fetch(PDO::FETCH_ASSOC))
{
// on rempli un tableau, en mettant l'id en index
$json[$donnees["USER_ID"]][] = utf8_encode($donnees["Nom"]);
}
}

// envoi du résultat au success
echo json_encode($json);


liste.js
jQuery(function($) {
$(document).ready(function()
{
var $vu_affect_empl = $('.th');
//intérrogation de la BDD en fesant appel script liste en php
$.ajax(
{
url: 'liste.php',
data: 'go', // on envoie $_GET['go']
dataType: 'json', // on veut un retour JSON
success: function(json)
{
$.each(json, function(affectation, value)
{
// pour chaque noeud JSON
// on ajoute l option dans la liste
$('.th').append('<option value="'+ affectation +'">'+ value +'</option>');
});
}
});
});
});


affection.html
<html>
<head>
<script type="text/javascript" src="liste.js"></script>
</head>

<body>
<form action="action_add.php" method="POST">
<select id="USER_ID" multiple class="th" title="Choisissez un ou plusieurs Thêmes" name="vu_affect_empl[]">
</select>
</form>
</body>

</html>
0
Rejoignez-nous