我有这个问题,它真的很简单,但就是想不通,代码太多了。我试图将 db 中的字段值回显到表列中,然后将它们添加为表中的行。
我希望你能看看有什么问题。
<?php
// First we execute our common code to connection to the database and start the session
require("common.php");
$sth = $db->prepare("SELECT * FROM coffee");
$sth->execute();
$row = $sth->fetch(PDO::FETCH_ASSOC);
//echo $row['field'];
//echo $row['apples'];
//echo $row['bananas'];
//echo $row['cherries'];
while($row = true){
$records = "<tr>
<td>".echo $rec['apples']."</td>
<td>".echo $rec['bananas']."</td>
<td>".echo $rec['cherries']."</td>
</tr>";
}
?>
<style type="text/css">
table.tftable {font-size:12px;color:#333333;width:100%;border-width: 1px;border-color: #9dcc7a;border-collapse: collapse;}
table.tftable th {font-size:12px;background-color:#abd28e;border-width: 1px;padding: 8px;border-style: solid;border-color: #9dcc7a;text-align:left;}
table.tftable tr {background-color:#ffffff;}
table.tftable td {font-size:12px;border-width: 1px;padding: 8px;border-style: solid;border-color: #9dcc7a;}
</style>
<table id="tfhover" class="tftable" border="1">
<tr><th>Apples</th><th>bananas</th><th>Cherries</th></tr>
<? print $records ?>
</table>