I was trying to display an array in php to an HTML table but there's an issue. I found several examples here in stack overflow, but they don't work for my case.
Controller:
<?php include('inc/db_connect.php');?>
<?php
try
{
$sql = "SELECT id GroupName, VideoTITLE, ByArtist FROM videoclip";
$result = $pdo->query($sql);
}
catch(PDOException $e)
{
$error = 'unable to fetch data: '.$e->getMessage();
include'error.html.php';
exit();
}
$URLS = array();
while ($row = $result->fetch())
{
$URLS[] = array('id' => $row['id'], 'GroupName' => $row['GroupName'], 'VideoTITLE' => $row['VideoTITLE'], 'ByArtist'=> $row['ByArtist'] );
}
html:
<div id="table_admin" class="span7">
<h3>Videoclip List</h3>
<table class="table table-striped table-condensed">
<thead>
<tr>
<th>Song name</th>
<th>Group name </th>
<th>Artist </th>
</tr>
</thead>
<?php foreach ($URLS as $URL){
echo'<tbody>';
echo'<tr>';
echo'<td>'. $row['VideoTITLE']."</td>";
echo'<td>'. $row['GroupName'].'</td>';
echo'<td>'. $row['ByArtist'].'</td>';
echo'<tr>';
echo'</tbody>';
}
?>
</table>
</div>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…