foreach 循环仅打印来自 MySQL table 的一条记录

foreach loop print only one record from MySQL table

我正在尝试使用 fpdf 将 table 的记录打印到 pdf 文件中,对此我在每个循环中使用,但它只打印一条记录,尽管它在没有 fpdf 的情况下工作正常 class.这是代码:

if(isset($_GET['show_id'])){
    $id = ($_GET['show_id']);
    $comments = selectAll('proposal_comment', ['proposal_id' => $id]);

    foreach($comments as $comment){
        $pdf = new FPDF();
        $pdf->AddPage();
        $pdf->SetFont('Arial','B',16);
        $pdf->Cell(100,10,$comment['message']);
        $pdf->Output();
    }
}

知道为什么会这样吗?

将初始化代码移到循环外,然后循环将只添加单元格

if(isset($_GET['show_id'])){
    $id = ($_GET['show_id']);
    $comments = selectAll('proposal_comment', ['proposal_id' => $id]);

    $pdf = new FPDF();
    $pdf->AddPage();
    $pdf->SetFont('Arial','B',16);

    foreach($comments as $comment){
        $pdf->Cell(100,10,$comment['message']);
    }

    $pdf->Output();
}