Récupérer les données d'une base de donnée dans un tableau.

Résolu
clement.enj Messages postés 8 Date d'inscription lundi 12 juin 2017 Statut Membre Dernière intervention 16 juin 2017 - Modifié le 25 nov. 2020 à 18:24
Sapht01 Messages postés 3 Date d'inscription mardi 24 novembre 2020 Statut Membre Dernière intervention 25 novembre 2020 - 25 nov. 2020 à 07:08
bonjour à tous :
je voudrai faire un tableau qui regroupe tout mes clients de mon hôtel.
cependant je ne vois vraiment pas comment faire. Les tutos sur internet sont mal fait. voici ce que je veux faire au final :
http://static.ccm2.net/codes-sources.commentcamarche.net/pictures/sNjH4UscLlHJSmHwmzQhZ3xrlUhVqvcZcHrcTVYK2HLOAobJyspwQo0bAvfFxNCW-capture.png

voilà mon début de code sauf qu'il ne fonctionne pas ...
si quelqu'un voit un autre moyen je serrai content de le voir :)
<?php 
require_once 'admin_inscription_connextion_bdd.php';
  $table = $pdo->prepare('SELECT idclient, nomclient, prenomclient, adresseclient, adressemail, login, nomville, codeville, telephone FROM clients');
  $table->execute();
  $table_bdd = $table->fetchall();
?>

p if(!empty($table_bdd)){
       echo "<table border='1'>\n";
       echo "<tr>\n";
       echo "<th><strong>Idclient</strong></th>\n";
       echo "<th><strong>Nom</strong></th>\n";
       echo "<th><strong>Prenom</strong></th>\n";
       echo "<th><strong>Adresse client</strong></th>\n";
       echo "<th><strong>email</strong></th>\n";
       echo "<th><strong>Login</strong></th>\n";
       echo "<th><strong>Ville</strong></th>\n";
       echo "<th><strong>Code Postal</strong></th>\n";
       echo "<th><strong>Téléphone</strong></th>\n";
       echo "</tr>\n";
            echo '<tr>';
            echo '<td bgcolor="#CCCCCC">'.$table_bdd["idclient"].'</td>';
            echo '<td bgcolor="#CCCCCC">'.$table_bdd["nomclient"].'</td>';
            echo '<td bgcolor="#CCCCCC">'.$table_bdd["prenomclient"].'</td>';
            echo '<td bgcolor="#CCCCCC">'.$table_bdd["adresseclient"].'</td>';
            echo '<td bgcolor="#CCCCCC">'.$table_bdd["adressemail"].'</td>';
            echo '</tr>'."\n";
            echo '</table>'."\n";// fin du tableau.
      }
      else{ echo 'Pas d\'enregistrements dans cette table...';

       
      }
     ?>


bonne soirée :)
A voir également:

3 réponses

raxos Messages postés 652 Date d'inscription lundi 29 décembre 2014 Statut Membre Dernière intervention 31 juillet 2022 3
Modifié le 25 nov. 2020 à 18:23
Bonjour,

J'ai fais ce code qui forme un tableau, si sa peut t'aider ;)

<!DOCTYPE html>
<html>
 <head>
  <meta charset="utf-8" />
  <title>Liste des fiches de procédures</title>
  <link rel="stylesheet" type="text/css" href="style.css" />
 </head>
 
 <body>
    <img src="logo.png" class="logo">
        <?php
  try  //Connection a la bdd
  {
   $bdd = new PDO('mysql:host=localhost;dbname=depannage;charset=utf8', 'root', 'xxxx');
  }
  catch (Exception $e)
  {
   die('Erreur : ' . $e->getMessage());
  }
  $reponse = $bdd->query('SELECT * FROM Tablette');
  
        echo '<center><div class="liste"><table>';
                 echo '<tr>';
      echo '<th class="thliste">N°</th>';
                     echo '<th class="thliste">Titre</th>';
                     echo '<th class="thliste">Etablissement</th>';
      echo '<th class="thliste">RNE</th>';
      echo '<th class="thliste">Type de matériel</th>';
                     echo '<th class="thliste">Etat</th>';
                 echo '</tr>';
   
            while($donnees = $reponse->fetch()) // Renvoit les valeurs de la bdd
            {
    echo '<tr>';
                    echo '<td class="tdliste">' . $donnees['id'] . '</td>';
        echo '<td class="tdliste">' . $donnees['titre'] . '</td>';
     echo '<td class="tdliste">' . $donnees['etablissement'] . '</td>';
     echo '<td class="tdliste">' . $donnees['RNE'] . '</td>';
     echo '<td class="tdliste">' . $donnees['Type de matériel'] . '</td>';
     echo '<td class="tdliste">' . $donnees['etat'] . '</td>';
    echo '</tr>';
            }
  echo '</table></div></center>';
            $pdo = null;
        ?>
  
    <p>
      
  <form action="ouverturefiche.php" method="post">
   Numéro de fiche :<input type="text" name="id" id="id" size="1px" />
  </form>
  <div class="bouton">
     <p>
       <a href="page1.html" rel="nofollow noopener noreferrer" target="_blank">Retour</a>
    </p>
  </div>
    </body>
</html>
2