0

I am a newbie programmer trying to figure out how to use PHP. I am developing a website where it is able to generate a form based on HTML and data from my PHP database. My concern here is that, after each page, I want the table named header to repeat after each page and a page number on the center bottom of each page. I tried accomplishing so using CSS and javascript however I have hit a brick wall. How do I suppose to adjust this? And yes I admit, maybe using composer would be an option however I am still figuring how to use it.

Code:

<?php

$mysqli = new mysqli($hostName, $userName, $password, $databaseName);

// Checking for connections
if ($mysqli->connect_error) {
    die('Connect Error (' .
        $mysqli->connect_errno . ') ' .
        $mysqli->connect_error);
}

$id = $_REQUEST['id'];

// Fetch data from bac1_files table
$query_files = "SELECT * FROM bac1_files WHERE id = '$id'";
$result_files = mysqli_query($mysqli, $query_files) or die(mysqli_error($mysqli));
$row_files = mysqli_fetch_assoc($result_files);

$timestamp = $row_files['timestamp'];
$pr = $row_files['PR'];
$rfq = $row_files['RFQ'];
$area = $row_files['Area'];
$itemdesc = $row_files['ItemDesc'];
$area = $row_files['Area'];
$delivery = $row_files['delivery'];

// Fetch data from bac1_rfq table
$query_rfq = "SELECT * FROM bac1_rfq WHERE file_id = '$id'"; // Update the condition to match the relationship between the tables
$result_rfq = mysqli_query($mysqli, $query_rfq) or die(mysqli_error($mysqli));

?>

<style>
  .no-spacing td {
    padding: 0;
    margin: 0;
  }

  .center-align {
    text-align: center;
  }

  .no-margin p {
    margin: 0;
  }

  table {
    font-size: 90%;
  }

  /* Styles for screen display */
  .hidden-on-print {
    display: none; /* or any other appropriate value for hiding */
  }

  /* Styles for print */
  @media print {
    .hidden-on-print {
      display: block;
    }

    /* Repeat the table with class "header" on each page */
    .header {
      display: table-header-group;
    }
  }

  /* Page number styles */
  .page-number {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10pt;
    color: #888;
  }
</style>

<div id="rfqgen" class="hidden-on-print">
<div class="page-container">
<table name="header" class="no-spacing" border="1" cellspacing="0" cellpadding="0">
  <tr>
    <td width="15%" rowspan="4" class="center-align">
      <img width="70%" src="../images/logo.jpg" alt="Image">
    </td>
    <td colspan="2" class="center-align">
      <br>
      <br>
      <b></b><br>
      Baguio City
    </td>
  </tr>
  <tr>
    <td width="55%" rowspan="3" class="center-align">
      Procurement Management Office<br>
      <b style="font-size:170%;">REQUEST FOR QUOTATION</b>
    </td>
    <td>
      <p>&nbsp;Form <span class="GramE">No. :</span> CMT-BAC-043</p>
    </td>
  </tr>
  <tr>
    <td>
      <p>&nbsp;Revision <span class="GramE">No. :</span> 3</p>
    </td>
  </tr>
  <tr>
    <td>
      <p>&nbsp;Effectivity <span class="GramE">Date :</span> May 2, 2023</p>
    </td>
  </tr>
</table>
<p>
<table>
  <tr>
    <td>Company Name:</td>
    <td style="border-bottom: 1px solid black; width:40%;"></td>
    <td>&nbsp;&nbsp;&nbsp;Date:</td>
    <th style="border-bottom: 1px solid black; width:40%;">&nbsp;
    <?php
    $formattedDate = date("F d, Y", strtotime($timestamp));
    echo $formattedDate;
    ?>
    </th>
  </tr>
  <tr>
    <td>Address:</td>
    <td style="border-bottom: 1px solid black;"></td>
    <td>&nbsp;&nbsp;&nbsp;PR No.:</td>
    <th style="border-bottom: 1px solid black;">&nbsp;<?php echo $pr;?></td>
  </tr>
  <tr>
    <td>Contact Number:</td>
    <td style="border-bottom: 1px solid black;"></td>
    <td>&nbsp;&nbsp;&nbsp;RFQ No.:</td>
    <th style="border-bottom: 1px solid black;">&nbsp;<?php echo $rfq;?></td>
  </tr>
  <tr>
    <td>Email Address:</td>
    <td style="border-bottom: 1px solid black;"></td>
    <td>&nbsp;&nbsp;&nbsp;End User:</td>
    <th style="border-bottom: 1px solid black;">&nbsp;<?php echo $area;?></td>
  </tr>
</table>

<table>
    <tr>
        <td>Sir/Ma'am:</td>
    </tr>
    <tr>
        <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Please quote your lowest government price for each of the following item(s) specified below. Submit your quotations, open or sealed, at the Procurement Management Office or thru <b>email at </b>, not later than ___________________. <u>Quotations received through email other than the email address provided <b>shall not be accepted.</b></u></td>
    </tr>
    <tr>
        <td>Terms and Conditions:</td>
    </tr>
    <tr>
        <td>1. The RFQ must be fully accomplished. Put 'N/A' to item/s that is not available.<br>
            2. Quotations shall be inclusive of applicable taxes and other indirect costs, those excedding the Approved Budget for the Contract (ABC) shall be automatically disqualified.<br>
            3. BAC reserves the right to reject any or all Quotations, to waive any minor defects therein, to annul the procurement process, to reject all Quotations at any time prior to the contract award, without thereby incurring any liability to the affected Bidder(s), and to accept only the offer that is most adavantageous to the Government.<br>
            4. <b><u>All quotations for drugs and medicines and medical supplies shall be accompanied by a valid Certificate of Product Registration (Non-submission shall result to supplier's POST-DISQUALIFICATION)</u></b><br>
            5. Delivery Schedule: <u>&nbsp;<b><?php echo $delivery;?></b>&nbsp;</u><br>
            6. Goods must be delivered at the Materials Management Office of BGHMC.<br>
        </td>
    </tr>
</table>
<p>
<table>
    <tr>
        <td><b>Additional Requirements (For new suppliers, to be submitted together with the quotation). -- These requirements shall likewise be submitted by all suppliers on the 1st month of the following year.</b></td>
    </tr>
</table>
<p>
<table class="no-spacing center-align" border="1" cellspacing="0" cellpadding="0" style="width:100%;">
    <tr>
        <td width=50%>Valid Business Permit/Mayor's Permit</td>
        <td width=50%>DTI/SEC Registration Certificate</td>
    </tr>
    <tr>
        <td>Certificate of PhilGEPS Registration</td>
        <td>Valid BIR Registration</td>
    </tr>
    <tr>
        <td>Omnibus Sworn Statement (using the Prescribed Form)</td>
        <td>BIR Form 2303</td>
    </tr>
</table>

<p>

  <table style="width:100%;">
    <tr>
      <td style="width:50%;"></td>
      <td>Truly yours,</td>
    </tr>
    <tr>
      <td></td>
    </tr>
    <tr>
      <td></td>
    </tr>
    <tr>
      <td></td>
      <td class="center-align" style="border-bottom: 1px solid black;"></td>
    </tr>
    <tr>
      <td></td>
      <td class="center-align">Head, Procurement Management Office</td>
    </tr>
  </table>


<p>
    <table>
        <tr>
            <td>*****************************************************************************************************************************</td>
        </tr>
    </table>
<table>
    <tr>
        <td>Sir/Madam:</td>
    </tr>
    <tr>
        <td>After having carefully read and accepted the terms and conditions stipulated in the Request for Quotation (RFQ), hereunder is our financial proposal inclusive of VAT and other incidental costs for the subject procurement identified below:</td>
    </tr>
</table>

<table class="no-spacing center-align" border="1" cellspacing="0" cellpadding="0" style="width:100%;">
  <tr>
    <th rowspan="2" width=5%>Item No.</th>
    <th rowspan="2" width=5%>Qty</th>
    <th rowspan="2" width=5%>Unit</th>
    <th rowspan="2" width=40%>Item Description</th>
    <th rowspan="2" width=10%>ABC/unit</th>
    <th rowspan="2" width=15%>Complete Specification<br>Offered<br>Brand Name/Model</th>
    <th colspan="2" width=20%>PRICE OFFER</th>
  </tr>
  <tr>
    <th>Unit Price</th>
    <th>Total Bid<br>Offer</th>
  </tr>

  <?php
  $totalAmount = 0; 
  $pageNumber = 1;
  // Loop through each row in bac2_rfq table and add a row to the table for each item
  while ($row_rfq = mysqli_fetch_assoc($result_rfq)) {
    $itemno = $row_rfq['itemno'];
    $item = $row_rfq['item'];
    $qty = $row_rfq['qty'];
    $unit = $row_rfq['unit'];
    $abcunit = $row_rfq['abcunit'];

    // Calculate the total amount
    $amount = $abcunit;
    $totalAmount += $amount;
    // Increment the page number
    $pageNumber++;

    ?>

    <tr>
      <td width=5% class="center-align"><?php echo $itemno; ?></td>
      <td width=5% class="center-align"><?php echo $qty; ?></td>
      <td width=5% class="center-align"><?php echo $unit; ?></td>
      <td width=40% style="text-align:left;padding-left:1%;"><?php echo $item; ?></td>
      <td width=10% class="center-align"><?php $amount = $abcunit; $formattedAmount = number_format($amount, 2, '.', ','); echo $formattedAmount; ?></td>
      <td width=15% class="center-align"></td>
      <td width=10.5% class="center-align"></td>
      <td width=10.5% class="center-align"></td>
    </tr>

  <?php
  }{
  ?>

<tr>
    <td colspan="4" style="text-align:right;"><b>Total:</b></td>
    <td class="center-align"><b><?php $formattedTotalAmount = number_format($totalAmount, 2, '.', ','); echo $formattedTotalAmount; ?></b></td>
    <td width=15% class="center-align"></td>
      <td width=10.5% class="center-align"></td>
      <td width=10.5% class="center-align"></td>
</tr>
<?php
  }
  ?>
</table>
<p>
    <table class="center-align" cellspacing="0" cellpadding="0" style="width:100%;">
        <tr>
            <th style="color:royalblue;"><u>For <?php echo $area;?> Use</u></th>
        </tr>
    </table>

    <p>

    <table>
        <tr>
            <td>We undertake, if our Quotation or bid is accepted, to accomplish the procurement project within the delivery schedule stipulated in the Purchase Order (PO).</td>
        </tr>
    </table>

    <div style="text-align: right;">
  <table style="width:100%;">
    <tr>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td></td>
      <td></td>
      <td></td>
    </tr>
    <tr>
      <td></td>
      <td style="text-align: right;">Signature:</td>
      <td style="border-bottom: 1px solid black; width:20%;"></td>
    </tr>
    <tr>
      <td></td>
      <td style="text-align: right;">Name of Representative:</td>
      <td style="border-bottom: 1px solid black; width:20%;"></td>
    </tr>
    <tr>
      <td></td>
      <td style="text-align: right;">Date:</td>
      <td style="border-bottom: 1px solid black; width:20%;"></td>
    </tr>
    <tr>
      <td></td>
      <td style="text-align: right;">RFQ No.:</td>
      <td style="border-bottom: 1px solid black; width:20%;">&nbsp;<b><?php echo $rfq;?><b></td>
    </tr>
  </table>
  </div>
</div>
</div>
  </div>

  <script>
  document.addEventListener("contextmenu", function(event) {
    event.preventDefault();
  });

  // Add page numbering using JavaScript
  window.onload = function() {
    var pages = document.getElementsByClassName("page-container")[0].children;
    var totalPages = pages.length;

    for (var i = 0; i < pages.length; i++) {
      pages[i].classList.add("hidden-on-print");
    }

    window.onbeforeprint = function() {
      var pageNumbers = "";

      for (var i = 0; i < totalPages; i++) {
        pageNumbers += "<span class='page-number'>Page " + (i + 1) + "</span>";
      }

      document.body.insertAdjacentHTML("beforeend", pageNumbers);
    };

    window.onafterprint = function() {
      var pageNumbers = document.getElementsByClassName("page-number");

      while (pageNumbers.length > 0) {
        pageNumbers[0].parentNode.removeChild(pageNumbers[0]);
      }
    };
  };
</script>

Vohn
  • 1
  • Html documents don't have any concept of pages. Are you talking about "printing" to a file? Your Web page has no knowledge of, and no control over, the size of the page that will be rendered by the print driver, any shrink or zoom the user might select, and this cannot know the amount of content which will fit on each page, and where to space things like footers and headers. If you want such fine control over the PDF output use a php library which can write directly to pdf and add custom code to get the layout exactly as you want, instead of relying on default browser functionality. – ADyson Jul 12 '23 at 14:02

0 Answers0