我遇到了这个问题并且它非常简单,但只是无法直接思考,代码太多了。我正在尝试将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>
答案 0 :(得分:0)
试试这个:
<table id="tfhover" class="tftable" border="1">
<tr><td>Apples</td><td>bananas</td><td>Cherries</td></tr>
<?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();
while ($row = $sth->fetch(PDO::FETCH_ASSOC))
{
?>
<tr>
<td><?=$row['apples']?></td>
<td><?=$row['bananas']?></td>
<td><?=$row['cherries']?></td>
</tr>
<?
}
?>
</table>