-1

我有这个问题,它真的很简单,但就是想不通,代码太多了。我试图将 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>
4

1 回答 1

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>
于 2013-06-28T21:11:02.770 回答