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 79 80 81 82 83 84 85 86 87 88
| <!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Tableau</title>
<link href="style.css" rel="stylesheet">
</head>
<body>
<!-- Connexion à la BDD -->
<?php
define("DBHOST", "localhost");
define("DBUSER", "root");
define("DBPASS", "");
define("DBNAME", "codpl_test2");
$dsn = "mysql:charset=utf8;dbname=".DBNAME.";host=".DBHOST;
try{
$db = new PDO($dsn, DBUSER, DBPASS);
}catch(PDOException $e){
die($e->getMessage());
}
//Préparation de la requete
$reponse = $db->query('SELECT DISTINCT C.ID, C.Prenom, C.Nom, C.Role, Q.ID_question FROM wp_contributeurs C LEFT OUTER JOIN questions_formulaire2 Q ON C.ID = Q.ID_personne');
while ($donnees = $reponse->fetch())
{
$role = $donnees['Role'];
$id = $donnees['ID'];
$id_question = $donnees['ID_question'];
?>
<table class="tableau">
<tr>
<td class="lignetableau"> <?php echo $donnees['ID']; ?> </td>
<td class="lignetableau"> <?php echo $donnees['Prenom']; ?> <?php echo $donnees['Nom']; ?></td>
<td class="lignetableau"> <?php echo $donnees['Role']; ?> </td>
<td class="lignetableau"> <?php echo $donnees['ID_question']; ?> </td>
<td class="lignetableau" id="LienNouveau"> <?php echo "<a href='http://localhost/CODPL/formulaire.php?role=$role&ID=$id&ID_question=$id_question'>Compléter votre avis</a> "; ?> </td>
<td class="lignetableau" id="LienModif"> <?php echo "<a href='http://localhost/CODPL/formulaire-modif.php?role=$role&ID=$id&ID_question=$id_question'>Consulter / Modifier</a> "; ?> </td>
</tr>
</table>
<?php
}
$reponse->closeCursor();
?>
<script>
//fonction JS pour affichage du bon lien dans le tableau
function affichelien()
{
//Récupération de la variable php id_question dans une variable JS
var formulaire = '<?php echo $id_question; ?>' ;
if (formulaire!== null && formulaire!== '')
{
document.getElementById('LienNouveau').style.display = 'block';
document.getElementById('LienModif').style.display = 'none';
}
else
{
document.getElementById('LienNouveau').style.display = 'none';
document.getElementById('LienModif').style.display = 'block';
}
}
affichelien()
</script>
</body>
</html> |
Partager