2014-02-15 15 views
0

這可能已經被回答,是的,我用谷歌,並在這裏計算器搜索,但問題依然存在,HTML PDF文件時對的foreach TCPDF基地,同時

我使用TCPDF庫生成PDF文件,它工作得很好,但我有以下的情況,爲了讓我的生成PDF OT只是HTML我需要把一些的foreach和同時的和如果HTML裏面的,這樣我可以拿到佈局用戶請求......

所以...

if(isset($_POST['submit'])) { 
$ids = htmlentities($_POST['id'], ENT_NOQUOTE; 
$con = conectionDB(); 
$query 'SELECT * FROM books WHERE id = "$ids"'; 
$doit = $con->query($query); 
// at this point everything is file 
// a few if's and we are done with the fetching "books" data 
// a few other tuff that is required from the library nothing fancy... 
// now here is the hard part 
// next line will build my layout to display my PDF 
$build_HTML = <<<EOD 
<style> 
.clasess {...} 
.nother {...} 
</style> 
<table width="100%" border="1" cellpadding="0" bordercolor="#333333" > 
<tr> 
<td>Author</td> 
<td>Books</td> 
</tr> 
<tr> 
<td> Jong </td> 
<td> 
<table> 
<tr> 
<td>Title</td><td>Year</td> 
</tr> 
// Here is the problem I need to put a query to fetch the related data from 
// another table 
$books = conectionDB(); 
$bookQ = "SELECT * FROM titles WHERE name = '$author_name'"; 
$doitTitles = $books->query($bookQ); 
if ($doitTitles->num_row > 1) { 
while($dos = $doitTitles->fetch_assoc()){ 
// my td's, but this doest work... 
} 
} 
</table> 
</td> 
</tr> 
</table> 
EOD; 
$pdf->writeHTML($build_HTML, true, false, false, false, ''); 
} else { 
// Go back... 
} 

正如你可以看到我需要一個查詢就在那裏,你可能有,我有$ doitTitles-通知> num_row> 1爲什麼呢?因爲如果有超過1絲毫不差的佈局會不同,如果只有1個記錄...

我們知道,這不會工作,這樣的問題是,是否有另一種方式來做到這一點?
現在,用戶去到PDF之前,我在顯示純HTML的信息,這意味着我的用戶之前使用HTML去到PDF將是相同的......所以我在想,有另一種圖書館,我可以用它來呈現HTML到PDF,而不是從文件中建立PDF ...該用戶能夠看到的結果使這些結果只是把「時間在一個PDF ...

謝謝您!

回答

0

我有解決方案,所以事情是,我試圖輸出,建立了動態​​內容的HTML,如果這是要顯示任何其他頁面,my_page.html是沒有問題的,但使用< <

$raw_html = 'Tables'; 
// a few while and foreach's and queries 
$raw_html .='Closed tables'; 
// Ready the HTML 
$html = <<<EOD 
$raw_html 
EOD; 
$pdf->writeHTML($html, true, false, false, false, ''); 
$pdf->Output('pdf_file_with_dynamic_html.pdf', 'I'); 
// the end. 

在輸出前準備HTML PDF它給了我,我需要,我需要的方式對數據...
上解決了我的問題。