-1

使用此代码将过去剧集列表添加到我的网站时:

包含.php

class rest {
  public function fetch_all(){
    global $pdo;
    $query = $pdo->prepare("SELECT * FROM podcast");
    $query->execute();
    return $query->fetchAll();
  }
}

索引.php

$rest = new rest;
$list = $rest->fetch_all();

<h2>Past Episodes<h2>
<?php foreach ($list as $rest) { ?>
<br><br>
<?php echo $cast['cast_title']; ?>

<?php } ?>

cast_title它显示 2 个相同(最新)的标题,而不是数据库字段中列出的 2 个单独的标题。

我错过了什么吗?

我通过添加对此进行排序

   <?php foreach ($articles as $feedback) {
if ($feedback['cast'] === $_GET['id']) { ?>
4

1 回答 1

2
class rest 
{
    public function fetch_all(){
        global $pdo;

        $query = $pdo->prepare("SELECT cast_title FROM podcast ORDER BY cast_title DESC");
        $query->execute();

        return $query->fetchAll();
    }
}

然后模板:

<?php
$rest = new rest;
?>

<h2>Past Episodes<h2>
<?php foreach ($rest->fetch_all() as $rest) { ?>
    <br><br>
    <?php echo $rest['cast_title']; ?>
<?php } ?>
于 2013-10-19T17:22:00.157 回答