-5

我有一个数据库,我想输出数据库的最后 5 行。该模型称为“文本”。

<?php for ($j = 0; $j < 5; $j++) { 

    ?>
    <tr>
        <td><?php echo $text['Text']['id']; ?></td>
        <td>
            <?php echo $text['Text']['expiration']; ?>
        </td>
        <td>
            <?php echo $text['Text']['title'] . " - " . $text['Text']['body']; ?>
        </td>
        <td><?php echo $text['Text']['created']; ?></td>
    </tr>
    <?php } ?>

这应该让你知道我在哪里。

4

1 回答 1

1

你必须使用find()

另一种方法是使用query()

$alltext = $this->Text->find('all', array('limit' => 5,'order'=>array('id DESC')));
<?php foreach ($alltextext as $text): ?>
 // format as necessary
<td><?php echo $text['Text']['id']; ?></td> 
// add others here
<?php endforeach; ?>
于 2012-04-14T03:38:02.440 回答