2017-03-27 6 views
0

Je veux un code pdo pour aller chercher les données de la base de données dans une table dynamiquement lorsque la page est ouverte.Il m'a fallu une journée entière mais je n'ai toujours pas reçu un code approprié OUT pdo code pour aller chercher des données dynamiquement dans un tableau

<div class="card"> 
      <div class="card-header"> 
       <h2>Selection Example <small>Ensure that the data attribute [data-identifier="true"] is set on one column header.</small></h2> 
      </div> 

      <table id="data-table-command" class="table table-striped table-vmiddle"> 
       <thead> 
        <tr> 
         <th data-column-id="id" data-type="numeric">ID</th> 
         <th data-column-id="sender">Sender</th> 
         <th data-column-id="received" data-order="desc">Received</th> 
         <th data-column-id="commands" data-formatter="commands" data-sortable="false">Commands</th> 
        </tr> 
       </thead> 
       <tbody> 
              <tr> 
         <td>10238</td> 
         <td>[email protected]</td> 
         <td>14.10.2013</td> 
        </tr> 
        <tr> 
         <td>10243</td> 
         <td>[email protected]</td> 
         <td>19.10.2013</td> 
        </tr> 
        <tr> 
         <td>10248</td> 
         <td>[email protected]</td> 
         <td>24.10.2013</td> 
        </tr> 
        <tr></tbody> 
      </table> 
     </div></div> 

Répondre

0
$data = $pdo->query("SELECT * FROM t")->fetchAll(); 
if ($data) { 
    echo "<table><tr>"; 
    foreach (array_keys($data[0] as $col)) { 
     echo "<th>$col</th>"; 
    } 
    echo "</tr>"; 
    foreach($pdo->query("SELECT * FROM t") as $row) { 
     echo "<tr>"; 
     foreach ($row as $col) { 
      echo "<td>$col</td>"; 
     } 
     echo "</tr>"; 
    } 
    echo "</table>"; 
} 
+0

Merci pour la solution, mais comment puis-je nourrir mes données dans le tableau ci-dessus à l'aide d'un appel de fonction lorsque la page est ouverte – Pihu