I am trying to output data in pdf. Upto 10 values code is working fine but it is not display 11th value and it is continuing from 12th value. Please help me fix it.
<?php
$result=mysqli_query($conn,"SELECT * FROM TABLE");
$Items = array();
while ($row = mysqli_fetch_assoc($result)) {
$Items[] = $row;
}
$x=0;
$y=0;
$a=5;
$b=5;
require('../pdf/alphapdf.php');
$pdf = new AlphaPDF();
$pdf->AddPage();
$title = 'Demo';
$pdf->SetTitle($title);
$pdf->SetLineWidth(1.5);
$pdf->SetAlpha(1);
foreach ($Items as $array) {
if($x<5){
$pdf->Image('abc.png',$a,$b,-300);
$pdf->SetFont('Arial', '', 9);
$pdf->Text($a,$b,$array['userName']);
$a=$a+58;
$x++;
}elseif($x>=5 && $x<10){
if($a>290){$a=5;}
$b=100;
$pdf->Image('abc.png',$a,$b,-300);
$pdf->SetFont('Arial', '', 9);
$pdf->Text($a,$b,$array['userName']);
$a=$a+58;
$x++;
}else{
$x=0;
$a=5;
$b=5;
$pdf->AddPage();
}
}
$pdf->Output();
?>
I know the issue is because of the else statement that i am using but i am not sure how to fix it.
$x > 10, you hit theelsestatement where you're adding a new page. But you don't then actually output the 11th item, you're moving on to process the 12th instead.