title: how to create multiple id cards dynamically in fpdf using php and mysql
body: <p>I was trying to create  id cards using fpdf in which the data to be plased in the id card is coming from mysql database and i have successfully made it the problem is that i want to generate many id card like 10 id cards once and when i try the blow code it is generating the id cards but placing one on the other and i can only see the last id card:</p>
  
  <p>A)so, how could i give them diffrent position for the id cards dynamically?
  below is my code and image showing the output:
  <a href="https://i.stack.imgur.com/XsvUf.jpg" rel="nofollow noreferrer">output image</a>    </p>
  
  <pre><code>  &lt;?php
           include('connect.php'); 
           require_once('fpdf/fpdf.php');
  
      if(ISSET($_POST['generate_id'])){   
              $semsec = $_POST['id']; 
      $result=$conn-&gt;query("SELECT * FROM `student` WHERE `semsec` = '$semsec'") or die(mysqli_error($conn));
      if ($result-&gt;num_rows == 0) {
          // output data of each row
       echo '
                      &lt;script type = "text/javascript"&gt;
                      alert("Student Not Found For The Provided Semister and Section");
                          window.location = "home.php";
                      &lt;/script&gt;
                  ';
      } else {
  
      while($row=mysqli_fetch_array($result))
      {
      $cls[]=$row;
      }
      $json=json_encode($cls);
      $obj = json_decode($json,true);
      class PDF extends FPDF
      {
  
      }
          $pdf = new PDF();
          $pdf-&gt;AddPage();
  
          foreach($obj as $item) {
  
          $name=$item['firstname'];
          $lname=$item['lastname'];
          $id=$item['student_no'];
          $semsec=$item['semsec'];
          $profile=$item['image'];
          $qr=$item['barcode'];
  
              $pdf-&gt;Image('images/background2.jpg', 10, 10,100, 50);
              $pdf-&gt;Image($profile, 80, 15,25, 30);
              $pdf-&gt;Image($qr, 15, 45,20, 15);
              $pdf-&gt;AddFont('courier','','courier.php');  
              $pdf-&gt;SetFont('courier','b',10);
              $pdf-&gt;SetXY(33, 22.8);
              $pdf-&gt;SetFont('Arial','B',10);
              $pdf-&gt;Cell(9.5,7,$name,0,4,'L');
              $pdf-&gt;SetXY(33, 28);
              $pdf-&gt;SetFont('Arial','B',10);
              $pdf-&gt;Cell(9.5,7,$lname,0,4,'L');
              $pdf-&gt;SetXY(33, 33.5);
              $pdf-&gt;SetFont('Arial','B',10);
              $pdf-&gt;Cell(9.5,7,$id,0,4,'L');
              $pdf-&gt;SetXY(33, 39);
              $pdf-&gt;SetFont('Arial','B',10);
              $pdf-&gt;Cell(9.5,7,$semsec,0,4,'L');
  
              }
      $pdf-&gt;Output();
      }
      }
  
      ?&gt;
  </code></pre>