auto populate serial number from and serial number to in laravel blade input code example

Example: serial number in pdf in html code using php

<?php  
 function fetch_data()  
 {  
      $output = '';  
      $conn = mysqli_connect("localhost", "root", "", "f1software"); 

        //$site_cd=$_POST['site_cd'];

      // $sql1 = "SELECT * FROM newsite";  
      // $result1 = mysqli_query($conn, $sql1);  

      $sql = "SELECT site_cd,item_cd,item_name,qty FROM newsite ORDER BY site_cd ASC";  
      $result = mysqli_query($conn, $sql);  
      while($row = mysqli_fetch_array($result))  
      {       
       
      $output .= '<tr>  
                          <td>1</td>  
                          <td>'.$row["site_cd"].'</td>  
                          <td>'.$row["item_cd"].'</td>  
                          <td>'.$row["item_name"].'</td>  
                          <td>'.$row["qty"].'</td>
                     </tr>  
                          ';  
      }  
 
      return $output;  
 }  
 if(isset($_POST["generate_pdf"]))  
 {  
        
      require_once('tcpdf/tcpdf.php');
      $obj_pdf = new TCPDF('P', PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);  
      $obj_pdf->SetCreator(PDF_CREATOR);  
      
      $obj_pdf->SetTitle("Quantity Availablity Report");  
      $obj_pdf->SetHeaderData('', '', PDF_HEADER_TITLE, PDF_HEADER_STRING);  
      $obj_pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));  
      $obj_pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));  
      $obj_pdf->SetDefaultMonospacedFont('helvetica');  
      $obj_pdf->SetFooterMargin(PDF_MARGIN_FOOTER);  
      $obj_pdf->SetMargins(PDF_MARGIN_LEFT, '10', PDF_MARGIN_RIGHT);  
      $obj_pdf->setPrintHeader(false);  
      $obj_pdf->setPrintFooter(false);  
      $obj_pdf->SetAutoPageBreak(TRUE, 10);  
      $obj_pdf->SetFont('helvetica', '', 11);  
      // $image = pdf_open_image_file($pdf, "jpeg", "https://www.iconfinder.com/data/icons/social-messaging-ui-color-shapes/128/document-circle-blue-512.png"); pdf_place_image($pdf, $image, 50, 650, 0.25);
      $obj_pdf->Image('https://icon2.cleanpng.com/20180624/qoc/kisspng-computer-icons-desktop-wallpaper-5b2ff7a8c65759.3456430915298702488124.jpg',10,-1,70);
      $obj_pdf->AddPage();  
      $content = '';  
      $content .= '  
      <h4 align="center" >Neelam Construction</h4><br /> 
      <table border="1" cellspacing="0" cellpadding="3">  
           <tr>  
                <th width="10%">Sr. No</th>
                <th  width="22.5%">Site Code</th>  
                <th width="22.5%">Item Code</th>  
                <th width="22.5%">Item Name</th>  
                <th width="22.5%">Total Qunatity</th>
                
           </tr>  
      ';  
      $content .= fetch_data();  
      $content .= '</table>';  
      $obj_pdf->writeHTML($content);  
      $obj_pdf->Output('file.pdf', 'I');  

 }  
 ?>  
 <!DOCTYPE html>  
 <html>  
      <head>  
           <title>SoftAOX | Generate HTML Table Data To PDF From MySQL Database Using TCPDF In PHP</title>  
           <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />    
          <style type="text/css">
            body
    {
    counter-reset: Serial;           /* Set the Serial counter to 0 */
    }
            tr td:first-child:before
    {
  counter-increment: Serial;      /* Increment the Serial counter */
  content: counter(Serial); /* Display the counter */
    }
          </style>

      </head>  
      <body>  
           <br />
           <div class="container">  
                <h4 align="center" > Generate HTML Table Data To PDF From MySQL Database Using TCPDF In PHP</h4><br />  
                <div class="table-responsive">  
                	<div class="col-md-12" align="right">
                     <form method="post">  
                          <input type="submit" name="generate_pdf" class="btn btn-success" value="Generate PDF" />  
                     </form>  
                     </div>
                     <br/>
                     <br/>
                     <table class="table table-bordered">  
                          <tr>  
                <th width="10%">Sr. No</th>              
                <th width="22.5%">Site Code</th>  
                <th width="22.5%">Item Code</th>  
                <th width="22.5%">Item Name</th>  
                <th width="22.5%">Total Qunatity</th>
                 
                
                          </tr>  
                     <?php  
                     echo fetch_data();  
                     ?>  
                     </table>  
                </div>  
           </div>  
      </body>  
 </html>

Tags:

Php Example