我希望我的数据库数据显示在表格中。我有以下代码,但它只是将所有内容粘贴在一起。
代码:
<?php
include ("core/db_connectie.php");
$template = file_get_contents("main.tpl.php");
$query = "SELECT * FROM platen";
$result = mysql_query($query) or die (mysql_error());
$cName = "";
$cValue = "";
while($row = mysql_fetch_assoc($result))
{
foreach($row as $columnName=>$columnValue)
{
$cName .= $columnName;
$cValue .= $columnValue;
}
}
$template = str_replace("%%header%%", "<tr><th>". $cName ."</tr></th>", $template);
$template = str_replace("%%data%%", "<tr><td>". $cValue ."</tr></td>", $template);
echo $template;
?>
在我的 HTML 文件中,我有:
<table>
%%header%%
%%data%%
</table>
我得到的结果是:
IDAlbumBandStijlMediumDatumPrijsIDAlbumBandStijlMediumDatumPrijs
1TestTestereRockLP2013-06-1202TestTestereRockLP2013-06-1213
但我希望它像:
ID Album Band Stijl Medium Datum Prijs
1 Test Test Rock LP 2013-06-1202 €10
2 Test Test Rock LP 2013-06-1202 €10