【发布时间】:2015-01-03 08:52:20
【问题描述】:
我正在尝试生成一个 .pdf 文件。但我无法连接我的文字: 这是我的代码:
<?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ó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");
?>
我认为我的错误在于下一行:
Nombre del cliente: <input type="text" value="'; //HERE I'M TRYING TO CONCATENATE
echo $datocli['nomempresacli'];
$codigoHTML='
">
我必须添加更多这样的行,但是如果它不能在一个中起作用,它不会在更多中起作用
有人可以帮我吗?
【问题讨论】:
-
警告:
mysql_query是一个过时的接口,不应在新的应用程序中使用,因为它会在未来的 PHP 版本中被删除。像PDO is not hard to learn 这样的现代替代品。如果您是 PHP 新手,PHP The Right Way 之类的指南可以帮助您解释最佳实践。 -
@tadman 我会考虑的,谢谢。
-
你没有附加/连接任何东西。您只是重新分配
$codigoHTML变量。要追加/连接,请使用.=运算符进行分配,例如$codigoHTML.="some text";。此外,回显变量会将其作为输出发送给用户,它不会附加到字符串。您也可以使用带有变量的.=附加。