2014-11-06 60 views
0

我正在嘗試生成.pdf文件。但我不能連接我的文字: 這是我的代碼:錯誤的pdf與DOMPDF

<?php 
include('conexion.php'); 
$con = conexion(); 
$sql="select * from [my table] where [condition] "; 
$res=mysql_query($sql,$con); 

$concli=conexion(); 
$sqlcli="select * from [my table] where [condition]"; 

$rescli=mysql_query($sqlcli,$concli); 
$datocli=mysql_fetch_array($rescli); 
$codigoHTML=' 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> 
<title>PDF</title> 
</head> 
<body> 

<form> 
<div align="left"> 
<img src="images/logo.jpg" width="186" height="88" alt="playss.net"/> </div><br/> 
<hr /> 
<div > 
<pre> 
Nombre del cliente: <input type="text" value="'; //HERE I'M TRYING TO CONCATENATE 
echo $datocli['nomempresacli']; 
$codigoHTML=' 
"> 
Nombre del Vendedor <input type="text" value=""> 
Proyecto:   <input type="text" > 
Fecha:    <input type="text" > 
</pre> 
<table width="95%" height="100%" border="1"> 
<tr height="40"> 
<td>#</td> 
<td >Id Producto</td> 
<td >Parte</td> 
<td >Descripci&oacute;n</td> 
<td >Cantidad</td> 
<td >Precio</td> 
<td >Subtotal</td> 
<td >Descuento</td> 
<td >total</td> 
</tr>'; 
require_once("dompdf/dompdf_config.inc.php"); 

$contador=1; 

while ($dato=mysql_fetch_array($res)) 
{ 
$codigoHTML.=' 
     <tr> 
     <td>'.$contador.'</td> 
     <td>'.$dato['idproducto'].'</td> 
     <td>'.$dato['parte'].'</td> 
     <td>'.$dato['descripcion'].'</td> 
     <td>'.$dato['cantidad'].'</td> 
     <td>'.$dato['precio'].'</td> 
     <td>'.$dato['subtotal'].'</td> 
     <td>'.$dato['descuento'].'</td> 
     <td>'.$dato['total'].'</td> 
     </tr>'; 
     $contador++; 
     } 
$codigoHTML.=' 
    </table> 
</div> 
<pre> 
<div align="right"> 
Total Final: <input type="text" > 
</div> 
</pre> 
<br/> 
<hr/> 


</form> 

</body> 
</html> 
'; 

$codigoHTML=utf8_decode($codigoHTML); 
$dompdf=new DOMPDF(); 
$dompdf->load_html($codigoHTML); 

ini_set("memory_limit","128M"); 
$dompdf->render(); 
$dompdf->stream("cotizacion.pdf"); 
?> 

img

我認爲的錯誤,我已經是在接下來的幾行:

Nombre del cliente: <input type="text" value="'; //HERE I'M TRYING TO CONCATENATE 
echo $datocli['nomempresacli']; 
$codigoHTML=' 
"> 

我要補充更多的線這樣的,但如果它不能在一個工作,它不會在更多的工作

有人可以幫助我嗎?

+1

** WARNING **: 'mysql_query'是一個過時的接口,不應該被使用在新的應用程序中,因爲它將在未來版本的PHP中被刪除。像[PDO這樣的現代化替代品並不難學](http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/)。如果您是PHP的新手,像[PHP The Right Way](http://www.phptherightway.com/)這樣的指南可以幫助解釋最佳實踐。 – tadman 2014-11-06 18:12:32

+0

@tadman我會將其考慮在內,謝謝。 – 2014-11-06 18:15:21

+0

您不追加/連接任何東西。你只是重新分配'$ codigoHTML'變量。要追加/連接,使用'。='運算符分配,例如'$ codigoHTML。=「某些文本」;'。此外,echo'ing一個變量發送給用戶作爲輸出,它不會附加到一個字符串。您也可以使用'。='附加一個變量。 – 2014-11-06 18:19:08

回答

0

的錯誤是你沒有contactenating最終的HTML結果正確:

用作這樣的:

Nombre del cliente: <input type="text" value="'; //HERE I'M TRYING TO CONCATENATE 
$codigoHTML.= $datocli['nomempresacli']; 
$codigoHTML.= ' 
"> 
Nombre del Vendedor <input type="text" value=""> 
Proyecto:   <input