使用 FPDF 在不同框中显示每个数据

我正在处理 fpdf,我想创建框并在不同的框中显示数据库中的每个数据。就像我有 2 个具有不同 XY 尺寸的框,所以我想在第一个框中显示值 1,在第二个框中显示值 2,但问题是当我使用我的代码时,它在两个框中都显示了值 1 和 2。我的代码是


$w = array(82,95); //for XY dimension

for($i=0;$i<2;$i++)

{

  $reusult1 = $GLOBALS['conn']->query($sql2);

  $queryresult=mysqli_num_rows($reusult1);

  $this->Rect($w[$i], 47.5, 13, 9);


  $this->SetXY($w[$i] , 47.5);

  $this->SetFont( "Arial", "", 9);


  while($rows = mysqli_fetch_assoc($reusult1)){


    $this->Cell(4,4,$rows['position'],1,0,'C');

 }

}

在$rows['position']有值1和2。


Smart猫小萌
浏览 144回答 1
1回答

慕桂英3389331

您的逻辑在两个 XY 位置循环两次并通过结果两次。我没有你的数据来测试这个,但它应该可以解决你的问题。$reusult1 = $GLOBALS['conn']->query($sql2);$w&nbsp; &nbsp; &nbsp; &nbsp; = array(82,95); //for XY dimensionfor($i=0; $i < 2; $i++) {&nbsp; $this->Rect($w[$i], 47.5, 13, 9);&nbsp; $this->SetXY($w[$i] , 47.5);&nbsp; $this->SetFont( "Arial", "", 9);&nbsp; $data = mysqli_fetch_assoc($reusult1);&nbsp; $this->Cell(4,4,$data['position'],1,0,'C');}&nbsp; // end of for loop
打开App,查看更多内容
随时随地看视频慕课网APP