我試圖在PHP中向一個HTML表格顯示一個數組。但似乎有一個問題。我在學習PHP的過程中,在堆棧溢出中找到幾個示例,但是不適合我的情況。 什麼是顯示結果並將其結合到HTML表格中的最佳方式?謝謝大家在Html表格中顯示Php數組結果
這裏的控制器:
<?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>
謝謝,這是一個個人項目,我正打算消毒之後,我完成建設,只是爲了確保我瞭解它的權利。謝謝,愚蠢的錯誤,我從來沒有看到,只是糾正它 –