2013-11-25 44 views
1

我有一個HTML表單,分爲3個部分(表格)。當我提交表單時,必須通過gen-czk-pdf.php中的PHP腳本來將HTML轉換爲PDF。每個表都有不確定的行數,我需要您的建議,我如何使用PHP列出來自每個表的所有這些行。如何使用PHP列出行數據

在calculate.php文件這是短表例子...

<form action="gen-czk-pdf.php" method="get" id="data" name="data"> 

<table class="items-table material-table" id="materialTable"> 
<tr> 
<td><textarea rows="2" id="materialItemName"></textarea></td> 
<td><input type="text" id="materialUnitPrice" /></td> 
<td><input type="text" id="materialItemQuantity" /></td> 
<td><input type="text" id="materialItemCoeff" /></td> 
<td><input type="text" id="materialItemPriceNoVat" /></td> 
<td><input type="text" id="materialItemVat" /></td> 
<td><input type="text" id="materialItemPriceInVat" /></td> 
</tr> 
</table> 

</form> 

在GEN-捷克克朗-pdf.php得到變量

$matName = $_GET['materialItemName']; 
$matPrPer = $_GET['materialUnitPrice']; 
$matQuant = $_GET['materialItemQuantity']; 
$matUnit = $_GET['materialUnitType']; 
$matCoeff = $_GET['materialItemCoeff']; 
$matItPrNoVat = $_GET['materialItemPriceNoVat']; 
$matItVat = $_GET['materialItemVat']; 
$matItPrInVat = $_GET['materialItemPriceInVat']; 

所以這是第一部分的一行我需要一個腳本,其中列出了一個部分(表格)的所有行。

+0

你是說這個輸入會產生int PDF ......和你問如何獲得HTML數據到PHP?我對嗎? – Denmark

+0

不,我的問題是,如何使用變量列出表格的每一行。有一些可能性嗎?在表中將是非指定的行數 – user2971509

+0

你的意思是你將獲得數據庫中的數據並將其顯示在表中? – Denmark

回答

0

庫:

<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 

class Dompdf_gen { 

    public function __construct() { 

     require_once APPPATH.'third_party/dompdf/dompdf_config.inc.php'; 

     $pdf = new DOMPDF(); 

     $CI =& get_instance(); 
     $CI->dompdf = $pdf; 

    } 

} 

控制器:

function pdf(){ 
      $container = array($matName => $_GET['materialItemName'], 
           $matPrPer => $_GET['materialUnitPrice'], 
           .....and next and next 
       ); 
        $data['transfer_data'] = $container; 
       $this->load->library('dompdf_gen'); 
       $html = $this->load->view('contracts/gen-czk-pdf', $data, true);//change the "contracts" to the folder where the " gen-czk-pdf" contained 
       $this->load->library('dompdf_gen'); 
       $dompdf = new DOMPDF(); 
       // Convert to PDF 
       $this->dompdf->load_html($html); 
       $this->dompdf->render(); 
       $this->dompdf->stream("Contract.pdf",array("Attachment"=>0)); // VIEW IN OTHER TAB 
       //$this->dompdf->stream("Contract.pdf"); // SAVE FILE TO DISK 
     } 

VIEW:

<table class="items-table material-table" id="materialTable"> 
<?php foreach($transfer_data as $data) : ?> 
    <tr> 
    <td><?=$data->materialItemName;?></td> 
    <td><?=$data->materialUnitPrice;?></td> 
    ............. 
    </tr> 
<?php endforeach; ?> 
</table> 

...我想我會給你的想法在我的代碼

0

改變你形成這一點。在GEN-捷克克朗-pdf.php

$item = $_POST['item'] 
foreach($item as $i) // iterate depend on how many table you put inside <form> 
{ 
    //$i == array of inputs 
    //  array(
    //   'materialItemName' => some value, 
    //   'materialUnitPrice' => some value, 
    //   ... 
    //   ) 
} 
0

<form action="gen-czk-pdf.php" method="get" id="data" name="data"> 

<table class="items-table material-table" id="materialTable"> 
<tr> 
<td><textarea rows="2" name="item[][materialItemName]"></textarea></td> 
<td><input type="text" name="item[][materialUnitPrice]" /></td> 
<td><input type="text" name="item[][materialItemQuantity]" /></td> 
<td><input type="text" name="item[][materialItemCoeff]" /></td> 
<td><input type="text" name="item[][materialItemPriceNoVat]" /></td> 
<td><input type="text" name="item[][materialItemVat]" /></td> 
<td><input type="text" name="item[][materialItemPriceInVat]" /></td> 
</tr> 
</table> 

</form> 

得到變量對於剛剛上市行的數據: - 抓鬥VARS

$matn = $_GET['materialItemName']; 
$matup = $_GET['materialUnitPrice']; 
$matq = $_GET['materialItemQuantity']; 
$matut = $_GET['materialUnitType']; 
$matic = $_GET['materialItemCoeff']; 
$matipnv = $_GET['materialItemPriceNoVat']; 
$mativ = $_GET['materialItemVat']; 
$matisv = $_GET['materialItemSumVat']; 
$matipiv = $_GET['materialPriceInVat']; 

- 和類型這樣的事情

$material_listing_data = ''; 
foreach($matn as $key => $matn) { 
    $material_listing_data = "<table><tr><td>". 
    $matn."</td><td>". 
     $matup[$key]."</td><td>". 
     $matq[$key]."</td><td>". 
     $matut[$key]."</td><td>". 
     $matic[$key]."</td></tr><tr><td>". 
     $matipnv[$key]."</td><td>". 
     $mativ[$key]."</td><td>". 
     $matisv[$key]."</td><td>". 
     $matipiv[$key]."</td></tr></table> 
     <br />"; 
    } 

$pdf->writeHTML($material_listing_data, true, false, true, false, ''); 
相關問題